Mercurial > octave
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 |
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 | 7 ## |
8 ## This file is part of Octave. | |
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 | 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 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
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 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 | 25 |
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 | 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 | 35 ## |
36 ## If @var{y} and @var{m} are specified, return the calendar for year @var{y} | |
37 ## and month @var{m}. | |
38 ## | |
39 ## If no output arguments are specified, print the calendar on the screen | |
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 | 42 ## @end deftypefn |
43 | |
44 ## Author: pkienzle <pkienzle@users.sf.net> | |
45 | |
46 function varargout = calendar (varargin) | |
47 | |
48 switch (nargin) | |
49 case 0 | |
50 v = clock (); | |
51 y = v(1); | |
52 m = v(2); | |
53 d = v(3); | |
54 case 1 | |
55 v = datevec (varargin{1}); | |
56 y = v(1); | |
57 m = v(2); | |
58 d = v(3); | |
59 case 2 | |
60 y = varargin{1}; | |
61 m = varargin{2}; | |
62 d = []; | |
63 otherwise | |
6046 | 64 print_usage (); |
5687 | 65 endswitch |
66 | |
67 c = zeros (7, 6); | |
68 dayone = datenum (y, m, 1); | |
69 ndays = eomday (y, m); | |
70 c(weekday (dayone) - 1 + [1:ndays]) = 1:ndays; | |
71 | |
72 if (nargout > 0) | |
73 varargout{1} = c'; | |
74 else | |
75 ## Layout the calendar days, 6 columns per day, 7 days per row. | |
76 str = sprintf (" %2d %2d %2d %2d %2d %2d %2d\n", c); | |
77 | |
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 | 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 | 83 endif |
84 | |
85 ## Display the calendar. | |
86 s.year = y - 1900; | |
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 | 91 endif |
92 | |
93 endfunction | |
94 | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
95 |
5687 | 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 | 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 | 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 | 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) |