annotate scripts/time/calendar.m @ 27981:7f1cec12c240

maint: Remove simple "Adapted-By:" lines from code base. * __ftp__.cc, urlwrite.cc, lin2mu.m, mu2lin.m, bincoeff.m, common_size.m, nextpow2.m, shift.m, xor.m, griddata.m, colormap.m, gray.m, gray2ind.m, image.m, imagesc.m, imshow.m, ind2gray.m, ind2rgb.m, ocean.m, rgb2ind.m, findstr.m, commutation_matrix.m, cross.m, gls.m, isdefinite.m, ishermitian.m, issymmetric.m, null.m, ols.m, orth.m, qzhess.m, vech.m, orderfields.m, untar.m, unzip.m, orient.m, __pltopt__.m, __gnuplot_print__.m, subplot.m, compan.m, conv.m, deconv.m, poly.m, polyder.m, polyfit.m, polyint.m, polyreduce.m, polyval.m, polyvalm.m, residue.m, roots.m, detrend.m, fftconv.m, fftfilt.m, fftshift.m, ifftshift.m, beta.m, lcm.m, pow2.m, corr.m, kurtosis.m, skewness.m, base2dec.m, bin2dec.m, blanks.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m, hex2dec.m, index.m, rindex.m, substr.m, calendar.m, datestr.m, datevec.m, eomday.m, now.m, weekday.m: Remove simple "Adapted-By:" lines from code base.
author Rik <rik@octave.org>
date Tue, 21 Jan 2020 13:15:15 -0800
parents bdad8ca48700
children 9f9ac219896d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 2004-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
7 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
5687
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 ## 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
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
19 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
20 ## 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: 6046
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
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 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20162
diff changeset
27 ## @deftypefn {} {@var{c} =} calendar ()
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20162
diff changeset
28 ## @deftypefnx {} {@var{c} =} calendar (@var{d})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20162
diff changeset
29 ## @deftypefnx {} {@var{c} =} calendar (@var{y}, @var{m})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20162
diff changeset
30 ## @deftypefnx {} {} calendar (@dots{})
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
31 ## Return the current monthly calendar in a 6x7 matrix.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
32 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
33 ## If @var{d} is specified, return the calendar for the month containing the
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
34 ## date @var{d}, which must be a serial date number or a date string.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
35 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
36 ## If @var{y} and @var{m} are specified, return the calendar for year @var{y}
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
37 ## and month @var{m}.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
38 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
39 ## If no output arguments are specified, print the calendar on the screen
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
40 ## instead of returning a matrix.
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
41 ## @seealso{datenum, datestr}
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
42 ## @end deftypefn
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
43
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
44 ## Author: pkienzle <pkienzle@users.sf.net>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
45
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
46 function varargout = calendar (varargin)
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 switch (nargin)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
49 case 0
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
50 v = clock ();
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
51 y = v(1);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
52 m = v(2);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
53 d = v(3);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
54 case 1
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
55 v = datevec (varargin{1});
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
56 y = v(1);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
57 m = v(2);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
58 d = v(3);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
59 case 2
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
60 y = varargin{1};
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
61 m = varargin{2};
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
62 d = [];
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
63 otherwise
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5687
diff changeset
64 print_usage ();
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
65 endswitch
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
66
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
67 c = zeros (7, 6);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
68 dayone = datenum (y, m, 1);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
69 ndays = eomday (y, m);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
70 c(weekday (dayone) - 1 + [1:ndays]) = 1:ndays;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
71
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
72 if (nargout > 0)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
73 varargout{1} = c';
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
74 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
75 ## Layout the calendar days, 6 columns per day, 7 days per row.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
76 str = sprintf (" %2d %2d %2d %2d %2d %2d %2d\n", c);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
77
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
78 ## Print an asterisk before the specified date
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
79 if (! isempty (d))
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
80 pos = weekday (dayone) + d - 1;
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
81 idx = 6*pos + fix (pos / 7.1) - ifelse (d < 10, 1, 2);
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
82 str(idx) = "*";
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
83 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
84
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
85 ## Display the calendar.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
86 s.year = y - 1900;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
87 s.mon = m - 1;
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
88 puts (strftime (" %b %Y\n", s));
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
89 puts (" S M Tu W Th F S\n");
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
90 puts (str);
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
91 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
92
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
93 endfunction
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
94
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
95
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
96 %!demo
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
97 %! ## Calendar for current month
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
98 %! calendar ()
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
99
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
100 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
101 %! ## Calendar for October, 1957
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
102 %! calendar (1957, 10)
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
103
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
104 %!assert ((calendar(2000,2))'(2:31), [0:29])
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
105 %!assert ((calendar(1957,10))'(2:33), [0:31])
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
106
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
107 ## Test input validation
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
108 %!error calendar (1,2,3)