annotate scripts/time/calendar.m @ 31191:bb9d776eafac stable

Fix wrong color in PDF printout of some latex strings (bug #62884) * octave-svgconvert (draw): For "rect" elements only set brush color if necessary and eventually restore to previous color.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sun, 14 Aug 2022 18:24:07 +0200
parents 796f54d4ddbf
children 5d3faba0342e
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
3 ## Copyright (C) 2004-2022 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 function varargout = calendar (varargin)
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 switch (nargin)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
47 case 0
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
48 v = clock ();
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
49 y = v(1);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
50 m = v(2);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
51 d = v(3);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
52 case 1
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
53 v = datevec (varargin{1});
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
54 y = v(1);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
55 m = v(2);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
56 d = v(3);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
57 case 2
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
58 y = varargin{1};
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
59 m = varargin{2};
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
60 d = [];
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
61 otherwise
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5687
diff changeset
62 print_usage ();
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
63 endswitch
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
64
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
65 c = zeros (7, 6);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
66 dayone = datenum (y, m, 1);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
67 ndays = eomday (y, m);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
68 c(weekday (dayone) - 1 + [1:ndays]) = 1:ndays;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
69
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
70 if (nargout > 0)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
71 varargout{1} = c';
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
72 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
73 ## 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
74 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
75
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
76 ## 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
77 if (! isempty (d))
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
78 pos = weekday (dayone) + d - 1;
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
79 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
80 str(idx) = "*";
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 ## Display the calendar.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
84 s.year = y - 1900;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
85 s.mon = m - 1;
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
86 puts (strftime (" %b %Y\n", s));
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
87 puts (" S M Tu W Th F S\n");
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
88 puts (str);
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
89 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
90
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
91 endfunction
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
92
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
93
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
94 %!demo
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
95 %! ## Calendar for current month
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
96 %! 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
97
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
98 %!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
99 %! ## Calendar for October, 1957
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
100 %! calendar (1957, 10)
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
101
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
102 %!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
103 %!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
104
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
105 ## Test input validation
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
106 %!error calendar (1,2,3)