annotate scripts/time/weekday.m @ 21546:f7f97d7e9294

doc: Wrap m-file docstrings to 79 characters + newline (80 total). * isrecording.m, soundsc.m, delaunay3.m, cell2mat.m, cumtrapz.m, del2.m, inputParser.m, interp1.m, interp3.m, narginchk.m, profile.m, validateattributes.m, delaunayn.m, tsearchn.m, voronoin.m, brighten.m, cmunique.m, colorcube.m, imfinfo.m, imshow.m, edit.m, orderfields.m, run.m, warning_ids.m, ode23.m, ode45.m, odeget.m, integrate_adaptive.m, kahan.m, ode_struct_value_check.m, runge_kutta_23.m, fminunc.m, fsolve.m, fzero.m, pkg.m, build.m, specular.m, view.m, bar.m, barh.m, contour3.m, isosurface.m, line.m, pie.m, pie3.m, quiver3.m, scatter.m, scatter3.m, stem3.m, stemleaf.m, surfl.m, tetramesh.m, isfigure.m, mkpp.m, pchip.m, residue.m, splinefit.m, rmpref.m, unique.m, eigs.m, ilu.m, factor.m, factorial.m, gallery.m, hankel.m, histc.m, ols.m, finv.m, fpdf.m, kruskal_wallis_test.m, weekday.m: Wrap m-file docstrings to 79 characters + newline (80 total).
author Rik <rik@octave.org>
date Sun, 27 Mar 2016 15:50:01 -0700
parents 77f5591878bf
children bac0d6f07a3e
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 -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20162
diff changeset
20 ## @deftypefn {} {[@var{n}, @var{s}] =} weekday (@var{d})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20162
diff changeset
21 ## @deftypefnx {} {[@var{n}, @var{s}] =} weekday (@var{d}, @var{format})
21546
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20955
diff changeset
22 ## Return the day of the week as a number in @var{n} and as a string in
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20955
diff changeset
23 ## @var{s}.
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
24 ##
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
25 ## 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
26 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
27 ## @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
28 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## 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
30 ## 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
31 ## @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
32 ##
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
33 ## 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
34 ##
14093
050bc580cb60 doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13856
diff changeset
35 ## @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
36 ## @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
37 ## @item 1 @tab Sun @tab Sunday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
38 ## @item 2 @tab Mon @tab Monday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
39 ## @item 3 @tab Tue @tab Tuesday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
40 ## @item 4 @tab Wed @tab Wednesday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
41 ## @item 5 @tab Thu @tab Thursday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
42 ## @item 6 @tab Fri @tab Friday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
43 ## @item 7 @tab Sat @tab Saturday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
44 ## @end multitable
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
45 ##
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
46 ## @seealso{eomday, is_leap_year, calendar, datenum, datevec}
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
47 ## @end deftypefn
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
48
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
49 ## Author: pkienzle <pkienzle@users.sf.net>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
50 ## Created: 10 October 2001 (CVS)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
51 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
52
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
53 function [d, s] = weekday (d, format = "short")
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
54
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
55 if (nargin < 1 || nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5687
diff changeset
56 print_usage ();
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
57 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
58
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
59 if (iscellstr (d) || isnumeric (d))
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
60 endsize = size (d);
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
61 elseif (ischar (d))
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
62 endsize = [rows(d), 1];
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
63 endif
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
64 if (ischar (d) || iscellstr (d))
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
65 ## Make sure the date is numeric
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
66 d = datenum (d);
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
67 endif
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
68 ## 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
69 d = floor (reshape (mod (d - 733048, 7), endsize));
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
70 ## Make Saturdays a 7 and not a 0.
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20852
diff changeset
71 d(! d) = 7;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
72
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
73 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
74 if (strcmpi (format, "long"))
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
75 names = {"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" ...
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 7434
diff changeset
76 "Friday" "Saturday"};
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
77 else
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
78 names = {"Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"};
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
79 endif
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
80 s = strvcat (names(d));
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
81 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
82
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
83 endfunction
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
84
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
85
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
86 %!demo
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
87 %! ## Current weekday
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
88 %! [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
89
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
90 %!demo
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
91 %! ## Weekday from datenum input
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
92 %! [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
93
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
94 %!demo
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
95 %! ## 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
96 %! [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
97
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
98 %!assert (weekday (728647), 2)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
99 ## 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
100 %!assert (weekday ([728647 728648]), [2 3])
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
101 %!assert (weekday ([728647;728648]), [2;3])
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
102 ## 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
103 %!assert (weekday ("19-Dec-1994"), 2)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
104 %!assert (weekday ("20-Dec-1994"), 3)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
105 %!assert (weekday ("21-Dec-1994"), 4)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
106 %!assert (weekday ("22-Dec-1994"), 5)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
107 %!assert (weekday ("23-Dec-1994"), 6)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
108 %!assert (weekday ("24-Dec-1994"), 7)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
109 %!assert (weekday ("25-Dec-1994"), 1)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
110 ## Test our reference day
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
111 %!assert (weekday ("6-Jan-2008"), 1)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
112 ## 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
113 %!assert (weekday ("1-Feb-2008"), 6)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
114 %!assert (weekday ("2-Feb-2008"), 7)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
115 %!assert (weekday ("3-Feb-2008"), 1)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
116 %!assert (weekday ("4-Feb-2008"), 2)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
117 %!assert (weekday ("5-Feb-2008"), 3)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
118 %!assert (weekday ("6-Feb-2008"), 4)
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
119 %!assert (weekday ("7-Feb-2008"), 5)
7434
600a3af7963e [project @ 2008-02-01 06:32:06 by jwe]
jwe
parents: 7017
diff changeset
120 ## Test fractional dates
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
121 %!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
122 ## Test "long" option
796dc1d75e06 Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11523
diff changeset
123 %!test
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
124 %! [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
125 %! assert (n, 1);
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13170
diff changeset
126 %! assert (s, "Sunday");
13170
796dc1d75e06 Fix incorrect newline in weekday.m (bug #34347)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11523
diff changeset
127