1## Copyright (C) 2004, 2006, 2007 Paul Kienzle
3## This file is part of Octave.
5## Octave is free software; you can redistribute it and/or modify it
6## under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 3 of the License, or (at
8## your option) any later version.
10## Octave is distributed in the hope that it will be useful, but
11## WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13## General Public License for more details.
15## You should have received a copy of the GNU General Public License
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
20## @deftypefn {Function File} {} calendar (@dots{})
21## @deftypefnx {Function File} {@var{c} =} calendar ()
22## @deftypefnx {Function File} {@var{c} =} calendar (@var{d})
23## @deftypefnx {Function File} {@var{c} =} calendar (@var{y}, @var{m})
24## If called with no arguments, return the current monthly calendar in
27## If @var{d} is specified, return the calendar for the month containing
28## the day @var{d}, which must be a serial date number or a date string.
30## If @var{y} and @var{m} are specified, return the calendar for year @var{y}
33## If no output arguments are specified, print the calendar on the screen
34## instead of returning a matrix.
38## Author: pkienzle <pkienzle@users.sf.net>
39## Created: 25 July 2004
40## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
42function varargout = calendar (varargin)
51 v = datevec (varargin{1});
64 dayone = datenum (y, m, 1);
65 ndays = eomday (y, m);
66 c(weekday (dayone) - 1 + [1:ndays]) = 1:ndays;
71 ## Layout the calendar days, 6 columns per day, 7 days per row.
72 str = sprintf (" %2d %2d %2d %2d %2d %2d %2d\n", c);
74 ## Print an asterisk before the specified date
75 if (! isempty (d) && d >= 1 && d <= ndays)
76 pos = weekday (dayone) + d - 1;
77 idx = 6 * (pos - 1) + floor (pos / 7) + 1;
78 while (str(idx) == " ")
84 ## Display the calendar.
87 puts (strftime (" %b %Y\n", s));
88 puts (" S M Tu W Th F S\n");
95%!assert((calendar(2000,2))'(2:31),[0:29]);
96%!assert((calendar(1957,10))'(2:33),[0:31]);
101%! calendar (1957, 10)