annotate scripts/time/weekday.m @ 20162:2645f9ef8c88 stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed specfun, special-matrix, testfun, and time script directories. * scripts/specfun/expint.m, scripts/specfun/isprime.m, scripts/specfun/legendre.m, scripts/specfun/primes.m, scripts/specfun/reallog.m, scripts/specfun/realsqrt.m, scripts/special-matrix/gallery.m, scripts/special-matrix/hadamard.m, scripts/special-matrix/hankel.m, scripts/special-matrix/hilb.m, scripts/special-matrix/invhilb.m, scripts/special-matrix/magic.m, scripts/special-matrix/pascal.m, scripts/special-matrix/rosser.m, scripts/special-matrix/toeplitz.m, scripts/special-matrix/vander.m, scripts/special-matrix/wilkinson.m, scripts/testfun/assert.m, scripts/testfun/demo.m, scripts/testfun/example.m, scripts/testfun/fail.m, scripts/testfun/rundemos.m, scripts/testfun/runtests.m, scripts/testfun/speed.m, scripts/time/asctime.m, scripts/time/calendar.m, scripts/time/clock.m, scripts/time/ctime.m, scripts/time/datenum.m, scripts/time/datestr.m, scripts/time/datevec.m, scripts/time/etime.m, scripts/time/is_leap_year.m, scripts/time/now.m, scripts/time/weekday.m: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Sun, 03 May 2015 17:00:11 -0700
parents 9fc020886ae9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19593
diff changeset
1 ## Copyright (C) 2000-2015 Paul Kienzle
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
2 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
4 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
8 ## your option) any later version.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
9 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
14 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
18
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {[@var{n}, @var{s}] =} weekday (@var{d})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
21 ## @deftypefnx {Function File} {[@var{n}, @var{s}] =} weekday (@var{d}, @var{format})
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
22 ## Return the day of the week as a number in @var{n} and as a string in @var{s}.
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
23 ##
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
24 ## The days of the week are numbered 1--7 with the first day being Sunday.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
25 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
26 ## @var{d} is a serial date number or a date string.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
27 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## If the string @var{format} is not present or is equal to @qcode{"short"}
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## then @var{s} will contain the abbreviated name of the weekday. If
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## @var{format} is @qcode{"long"} then @var{s} will contain the full name.
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
31 ##
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
32 ## Table of return values based on @var{format}:
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
33 ##
14093
050bc580cb60 doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13856
diff changeset
34 ## @multitable @columnfractions .06 .13 .16
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 14237
diff changeset
35 ## @headitem @var{n} @tab @qcode{"short"} @tab @qcode{"long"}
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
36 ## @item 1 @tab Sun @tab Sunday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
37 ## @item 2 @tab Mon @tab Monday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
38 ## @item 3 @tab Tue @tab Tuesday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
39 ## @item 4 @tab Wed @tab Wednesday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
40 ## @item 5 @tab Thu @tab Thursday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
41 ## @item 6 @tab Fri @tab Friday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
42 ## @item 7 @tab Sat @tab Saturday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
43 ## @end multitable
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
44 ##
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
45 ## @seealso{eomday, is_leap_year, calendar, datenum, datevec}
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
46 ## @end deftypefn
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
47
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
48 ## Author: pkienzle <pkienzle@users.sf.net>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
49 ## Created: 10 October 2001 (CVS)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
50 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
51
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
52 function [d, s] = weekday (d, format = "short")
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
53
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
54 if (nargin < 1 || nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5687
diff changeset
55 print_usage ();
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
56 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
57
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
58 if (iscellstr (d) || isnumeric (d))
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
59 endsize = size (d);
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
60 elseif (ischar (d))
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
61 endsize = [rows(d), 1];
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
62 endif
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
63 if (ischar (d) || iscellstr (d))
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
64 ## Make sure the date is numeric
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
65 d = datenum (d);
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
66 endif
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
67 ## Find the offset from a known Sunday (2008-Jan-6), mod 7.
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
68 d = floor (reshape (mod (d - 733048, 7), endsize));
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
69 ## Make Saturdays a 7 and not a 0.
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
70 d(!d) = 7;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
71
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
72 if (isargout (2))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
73 if (strcmpi (format, "long"))
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
74 names = {"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7434
diff changeset
75 "Friday" "Saturday"};
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
76 else
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
77 names = {"Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"};
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
78 endif
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
79 s = strvcat (names(d));
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
80 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
81
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
82 endfunction
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
83
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
84
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
85 %!demo
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
86 %! ## Current weekday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
87 %! [n, s] = weekday (now ())
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
88
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
89 %!demo
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
90 %! ## Weekday from datenum input
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
91 %! [n, s] = weekday (728647)
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
92
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
93 %!demo
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
94 %! ## Weekday of new millennium from datestr input
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
95 %! [n, s] = weekday ("1-Jan-2000")
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
96
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
97 %!assert (weekday (728647), 2)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
98 ## Test vector inputs for both directions
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
99 %!assert (weekday ([728647 728648]), [2 3])
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
100 %!assert (weekday ([728647;728648]), [2;3])
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
101 ## Test a full week before our reference day
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
102 %!assert (weekday ("19-Dec-1994"), 2)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
103 %!assert (weekday ("20-Dec-1994"), 3)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
104 %!assert (weekday ("21-Dec-1994"), 4)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
105 %!assert (weekday ("22-Dec-1994"), 5)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
106 %!assert (weekday ("23-Dec-1994"), 6)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
107 %!assert (weekday ("24-Dec-1994"), 7)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
108 %!assert (weekday ("25-Dec-1994"), 1)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
109 ## Test our reference day
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
110 %!assert (weekday ("6-Jan-2008"), 1)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
111 ## Test a full week after our reference day
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
112 %!assert (weekday ("1-Feb-2008"), 6)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
113 %!assert (weekday ("2-Feb-2008"), 7)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
114 %!assert (weekday ("3-Feb-2008"), 1)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
115 %!assert (weekday ("4-Feb-2008"), 2)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
116 %!assert (weekday ("5-Feb-2008"), 3)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
117 %!assert (weekday ("6-Feb-2008"), 4)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
118 %!assert (weekday ("7-Feb-2008"), 5)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
119 ## Test fractional dates
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
120 %!assert (weekday (728647.1), 2)
13170
796dc1d75e06 Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11523
diff changeset
121 ## Test "long" option
796dc1d75e06 Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11523
diff changeset
122 %!test
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
123 %! [n, s] = weekday ("25-Dec-1994", "long");
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
124 %! assert (n, 1);
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
125 %! assert (s, "Sunday");
13170
796dc1d75e06 Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11523
diff changeset
126