changeset 13856:d490ca8ab1a5

Modernize function implementations and docstrings in scripts/time. * addtodate.m: Add millisecond functionality. Update docstring and %!tests. * calendar.m: Implement faster way to add '*' to day display. Update docstring. * weekday.m: Use more modern coding stytle. Update docstring. * asctime.m, clock.m, ctime.m, date.m, datenum.m, datestr.m, datevec.m, eomday.m, etime.m, is_leap_year.m: Update docstring and/or use Octave formatting spacing conventions for %!tests.
author Rik <octave@nomad.inbox5.com>
date Thu, 10 Nov 2011 13:35:08 -0800
parents 5050e92dc25a
children 9f28f0d05473
files scripts/time/addtodate.m scripts/time/asctime.m scripts/time/calendar.m scripts/time/clock.m scripts/time/ctime.m scripts/time/date.m scripts/time/datenum.m scripts/time/datestr.m scripts/time/datevec.m scripts/time/eomday.m scripts/time/etime.m scripts/time/is_leap_year.m scripts/time/now.m scripts/time/weekday.m
diffstat 14 files changed, 214 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/time/addtodate.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/addtodate.m	Thu Nov 10 13:35:08 2011 -0800
@@ -18,32 +18,32 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {@var{d} =} addtodate (@var{d}, @var{q}, @var{f})
-## Add @var{q} amount of time (with units @var{f}) to the datenum, @var{d}.
+## Add @var{q} amount of time (with units @var{f}) to the serial datenum, @var{d}.
 ##
-## @var{f} must be one of "year", "month", "day", "hour", "minute", or
-## "second".
-## @seealso{datenum, datevec}
+## @var{f} must be one of "year", "month", "day", "hour", "minute", "second",
+## or "millisecond".
+## @seealso{datenum, datevec, etime}
 ## @end deftypefn
 
 ## Author: Bill Denney <bill@denney.ws>
 
 function d = addtodate (d, q, f)
 
+  persistent mult = struct ("day", 1, "hour", 1/24, "minute", 1/1440, ...
+                            "second", 1/86400, "millisecond", 1/86400000);
+
   if (nargin != 3)
     print_usage ();
-  elseif (! (ischar (f) && rows (f) == 1))
-    ## FIXME: enhance the function so that it works with cellstrs of the
-    ## same size as the output.
-    error ("addtodate: F must be a single row character string");
+  elseif (! (ischar (f) && isrow (f)))
+    error ("addtodate: F must be a single character string");
   endif
 
-  if (numel (d) == 1 && numel (q) > 1)
-    ## expand d to the size of q if d only has one element to make
-    ## addition later eaiser.
-    d = d.*ones (size (q));
+  if (isscalar (d) && ! isscalar (q))
+    ## expand d to size of q to make later addition easier.
+    d = repmat (d, size (q));
   endif
 
-  ## in case the user gives f as a plural, remove the s
+  ## in case the user gives f as a plural, remove the 's'
   if ("s" == f(end))
     f(end) = [];
   endif
@@ -65,15 +65,15 @@
     else
       d = reshape (dnew, size (q));
     endif
-  elseif (any (strcmpi ({"day" "hour" "minute" "second"}, f)))
-    mult = struct ("day", 1, "hour", 1/24, "minute", 1/1440, "second", 1/86400);
-    d += q.*mult.(f);
+  elseif (any (strcmpi ({"day" "hour" "minute" "second", "millisecond"}, f)))
+    d += q .* mult.(f);
   else
     error ("addtodate: Invalid time unit: %s", f);
   endif
 
 endfunction
 
+
 ## tests
 %!shared d
 %!  d = datenum (2008, 1, 1);
@@ -84,6 +84,7 @@
 %!assert (addtodate (d, 0, "hour"), d)
 %!assert (addtodate (d, 0, "minute"), d)
 %!assert (addtodate (d, 0, "second"), d)
+%!assert (addtodate (d, 0, "millisecond"), d)
 ## Add one of each
 ## leap year
 %!assert (addtodate (d, 1, "year"), d+366)
@@ -92,6 +93,7 @@
 %!assert (addtodate (d, 1, "hour"), d+1/24)
 %!assert (addtodate (d, 1, "minute"), d+1/1440)
 %!assert (addtodate (d, 1, "second"), d+1/86400)
+%!assert (addtodate (d, 1, "millisecond"), d+1/86400000)
 ## substract one of each
 %!assert (addtodate (d, -1, "year"), d-365)
 %!assert (addtodate (d, -1, "month"), d-31)
@@ -99,6 +101,7 @@
 %!assert (addtodate (d, -1, "hour"), d-1/24)
 %!assert (addtodate (d, -1, "minute"), d-1/1440)
 %!assert (addtodate (d, -1, "second"), d-1/86400)
+%!assert (addtodate (d, -1, "millisecond"), d-1/86400000)
 ## rollover
 %!assert (addtodate (d, 12, "month"), d+366)
 %!assert (addtodate (d, 13, "month"), d+366+31)
@@ -109,3 +112,13 @@
 %!assert (addtodate (d, [1 13], "month"), [d+31 d+366+31])
 %!assert (addtodate ([d;d+1], 1, "month"), [d+31;d+1+31])
 %!assert (addtodate ([d d+1], 1, "month"), [d+31 d+1+31])
+
+%% Test input validation
+%!error addtodate ()
+%!error addtodate (1)
+%!error addtodate (1,2)
+%!error addtodate (1,2,3,4)
+%!error <F must be a single character string> addtodate (1,2,3)
+%!error <F must be a single character string> addtodate (1,2,"month"')
+%!error <Invalid time unit> addtodate (1,2,"abc")
+
--- a/scripts/time/asctime.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/asctime.m	Thu Nov 10 13:35:08 2011 -0800
@@ -18,36 +18,37 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} asctime (@var{tm_struct})
-## Convert a time structure to a string using the following five-field
-## format: Thu Mar 28 08:40:14 1996.  For example:
+## Convert a time structure to a string using the following 
+## format: "ddd mmm mm HH:MM:SS yyyy".  For example:
 ##
 ## @example
 ## @group
 ## asctime (localtime (time ()))
-##      @result{} "Mon Feb 17 01:15:06 1997\n"
+##      @result{} "Mon Feb 17 01:15:06 1997"
 ## @end group
 ## @end example
 ##
 ## This is equivalent to @code{ctime (time ())}.
+## @seealso{ctime, localtime, time}
 ## @end deftypefn
 
 ## Author: jwe
 
 function retval = asctime (tm_struct)
 
-  if (nargin == 1)
-    retval = strftime ("%a %b %d %H:%M:%S %Y\n", tm_struct);
-  else
+  if (nargin != 1)
     print_usage ();
   endif
 
+  retval = strftime ("%a %b %d %H:%M:%S %Y\n", tm_struct);
+
 endfunction
 
+
 %!test
 %! t = time ();
 %! assert(strcmp (asctime (localtime (t)), ctime (t)));
 
 %!error asctime ();
-
 %!error asctime (1, 2);
 
--- a/scripts/time/calendar.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/calendar.m	Thu Nov 10 13:35:08 2011 -0800
@@ -17,22 +17,21 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} calendar (@dots{})
-## @deftypefnx {Function File} {@var{c} =} calendar ()
+## @deftypefn  {Function File} {@var{c} =} calendar ()
 ## @deftypefnx {Function File} {@var{c} =} calendar (@var{d})
 ## @deftypefnx {Function File} {@var{c} =} calendar (@var{y}, @var{m})
-## If called with no arguments, return the current monthly calendar in
-## a 6x7 matrix.
+## @deftypefnx {Function File} {} calendar (@dots{})
+## Return the current monthly calendar in a 6x7 matrix.
 ##
 ## If @var{d} is specified, return the calendar for the month containing
-## the day @var{d}, which must be a serial date number or a date string.
+## the date @var{d}, which must be a serial date number or a date string.
 ##
 ## If @var{y} and @var{m} are specified, return the calendar for year @var{y}
 ## and month @var{m}.
 ##
 ## If no output arguments are specified, print the calendar on the screen
 ## instead of returning a matrix.
-## @seealso{datenum}
+## @seealso{datenum, datestr}
 ## @end deftypefn
 
 ## Author: pkienzle <pkienzle@users.sf.net>
@@ -72,13 +71,10 @@
     str = sprintf ("    %2d    %2d    %2d    %2d    %2d    %2d    %2d\n", c);
 
     ## Print an asterisk before the specified date
-    if (! isempty (d) && d >= 1 && d <= ndays)
+    if (! isempty (d))
       pos = weekday (dayone) + d - 1;
-      idx = 6 * (pos - 1) + floor (pos / 7) + 1;
-      while (str(idx) == " ")
-        ++idx;
-      endwhile
-      str(--idx) = "*";
+      idx = 6*pos + fix (pos / 7.1) - ifelse (d < 10, 1, 2);
+      str(idx) = "*";
     endif
 
     ## Display the calendar.
@@ -91,11 +87,18 @@
 
 endfunction
 
-# tests
-%!assert((calendar(2000,2))'(2:31),[0:29]);
-%!assert((calendar(1957,10))'(2:33),[0:31]);
-# demos
+
+## demos
 %!demo
+%! ## Calendar for current month
 %! calendar ()
 %!demo
 %! calendar (1957, 10)
+
+## tests
+%!assert ((calendar(2000,2))'(2:31), [0:29])
+%!assert ((calendar(1957,10))'(2:33), [0:31])
+
+%% Test input validation
+%!error calendar (1,2,3)
+
--- a/scripts/time/clock.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/clock.m	Thu Nov 10 13:35:08 2011 -0800
@@ -18,18 +18,23 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} clock ()
-## Return a vector containing the current year, month (1-12), day (1-31),
-## hour (0-23), minute (0-59) and second (0-61).  For example:
+## Return the current local date and time as a date vector.  The date vector
+## contains the following fields: current year, month (1-12), day (1-31),
+## hour (0-23), minute (0-59), and second (0-61).  The seconds field has
+## a fractional part after the decimal point for extended accuracy.
+##
+## For example:
 ##
 ## @example
 ## @group
-## clock ()
+## fix (clock ())
 ##      @result{} [ 1993, 8, 20, 4, 56, 1 ]
 ## @end group
 ## @end example
 ##
 ## The function clock is more accurate on systems that have the
 ## @code{gettimeofday} function.
+## @seealso{now, date, datevec}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/time/ctime.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/ctime.m	Thu Nov 10 13:35:08 2011 -0800
@@ -26,28 +26,29 @@
 ## @example
 ## @group
 ## ctime (time ())
-##      @result{} "Mon Feb 17 01:15:06 1997\n"
+##      @result{} "Mon Feb 17 01:15:06 1997"
 ## @end group
 ## @end example
+## @seealso{asctime, time, localtime}
 ## @end deftypefn
 
 ## Author: jwe
 
 function retval = ctime (t)
 
-  if (nargin == 1)
-    retval = asctime (localtime (t));
-  else
+  if (nargin != 1)
     print_usage ();
   endif
 
+  retval = asctime (localtime (t));
+
 endfunction
 
+
 %!test
 %! t = time ();
 %! assert(strcmp (asctime (localtime (t)), ctime (t)));
 
 %!error ctime ();
-
 %!error ctime (1, 2);
 
--- a/scripts/time/date.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/date.m	Thu Nov 10 13:35:08 2011 -0800
@@ -18,15 +18,17 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} date ()
-## Return the date as a character string in the form DD-MMM-YY@.  For
-## example:
+## Return the current date as a character string in the form DD-MMM-YYYY@.
+##
+## For example:
 ##
 ## @example
 ## @group
 ## date ()
-##      @result{} "20-Aug-93"
+##      @result{} "20-Aug-1993"
 ## @end group
 ## @end example
+## @seealso{now, clock, datestr, localtime}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/time/datenum.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/datenum.m	Thu Nov 10 13:35:08 2011 -0800
@@ -26,16 +26,23 @@
 ## @deftypefnx {Function File} {@var{days} =} datenum ("datestr", @var{p})
 ## @deftypefnx {Function File} {[@var{days}, @var{secs}] =} datenum (@dots{})
 ## Return the date/time input as a serial day number, with Jan 1, 0000
-## being day 1.  The fractional portion of @var{days} corresponds to the time
-## on the given day.  The input may be a date vector (see @code{datevec}), 
+## defined as day 1.
+##
+## The integer part, @code{floor (@var{days})} counts the number of
+## complete days in the date input.
+##
+## The fractional part, @code{rem (@var{days}, 1)} corresponds to the time
+## on the given day.
+##
+## The input may be a date vector (see @code{datevec}), 
 ## datestr (see @code{datestr}), or directly specified as input.
 ##
-## When processing datestrings, @var{p} is the year at the start of the century
-## to which two-digit years will be referenced.  If not specified, it defaults
-## to the current year minus 50.
+## When processing input datestrings, @var{p} is the year at the start of the
+## century to which two-digit years will be referenced.  If not specified, it
+## defaults to the current year minus 50.
 ##
-## The optional output @var{secs} holds the time on the specified day with greater
-## precision than @var{days}.
+## The optional output @var{secs} holds the time on the specified day with
+## greater precision than @var{days}.
 ##
 ## Notes:
 ##
@@ -68,7 +75,7 @@
 ##
 ## @strong{Warning:} leap seconds are ignored.  A table of leap seconds
 ## is available on the Wikipedia entry for leap seconds.
-## @seealso{datestr, datevec, date, clock, now, calendar, weekday}
+## @seealso{datestr, datevec, now, clock, date}
 ## @end deftypefn
 
 ## Algorithm: Peter Baum (http://vsg.cape.com/~pbaum/date/date0.htm)
--- a/scripts/time/datestr.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/datestr.m	Thu Nov 10 13:35:08 2011 -0800
@@ -103,7 +103,7 @@
 ## If a matrix or cell array of dates is given, a column vector of date strings
 ## is returned.
 ##
-## @seealso{datenum, datevec, date, clock, now}
+## @seealso{datenum, datevec, date, now, clock}
 ## @end deftypefn
 
 ## FIXME: parse arbitrary code strings.
--- a/scripts/time/datevec.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/datevec.m	Thu Nov 10 13:35:08 2011 -0800
@@ -34,7 +34,7 @@
 ## @var{p} is the year at the start of the century to which two-digit years
 ## will be referenced.  If not specified, it defaults to the current year
 ## minus 50.
-## @seealso{datenum, datestr, date, clock, now}
+## @seealso{datenum, datestr, clock, now, date}
 ## @end deftypefn
 
 ## Algorithm: Peter Baum (http://vsg.cape.com/~pbaum/date/date0.htm)
--- a/scripts/time/eomday.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/eomday.m	Thu Nov 10 13:35:08 2011 -0800
@@ -19,7 +19,7 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {@var{e} =} eomday (@var{y}, @var{m})
 ## Return the last day of the month @var{m} for the year @var{y}.
-## @seealso{datenum, datevec, weekday}
+## @seealso{weekday, datenum, datevec, is_leap_year, calendar}
 ## @end deftypefn
 
 ## Author: pkienzle <pkienzle@users.sf.net>
@@ -38,20 +38,28 @@
 
 endfunction
 
+
+%!demo
+%! ## Find leap years in the 20th century
+%! y = 1900:1999;
+%! e = eomday (y, repmat (2, [1, 100]));
+%! y(find (e == 29))
+
 # tests
-%!assert(eomday([-4:4],2),[29,28,28,28,29,28,28,28,29])
-%!assert(eomday([-901,901],2),[28,28])
-%!assert(eomday([-100,100],2),[28,28])
-%!assert(eomday([-900,900],2),[28,28])
-%!assert(eomday([-400,400],2),[29,29])
-%!assert(eomday([-800,800],2),[29,29])
-%!assert(eomday(2001,1:12),[31,28,31,30,31,30,31,31,30,31,30,31])
-%!assert(eomday(1:3,1:3),[31,28,31])
-%!assert(eomday(1:2000,2)',datevec(datenum(1:2000,3,0))(:,3))
-%!assert([1900:1999](find(eomday(1900:1999,2*ones(1,100))==29)),[1904,1908,1912,1916,1920,1924,1928,1932,1936,1940,1944,1948,1952,1956,1960,1964,1968,1972,1976,1980,1984,1988,1992,1996])
-%!assert(eomday([2004;2005], [2;2]), [29;28])
-# demos
-%!demo
-%! y = 1900:1999;
-%! e = eomday (y, 2 * ones (1, 100));
-%! y (find (e == 29))
+%!assert (eomday ([-4:4],2), [29,28,28,28,29,28,28,28,29])
+%!assert (eomday ([-901,901],2), [28,28])
+%!assert (eomday ([-100,100],2), [28,28])
+%!assert (eomday ([-900,900],2), [28,28])
+%!assert (eomday ([-400,400],2), [29,29])
+%!assert (eomday ([-800,800],2), [29,29])
+%!assert (eomday (2001,1:12), [31,28,31,30,31,30,31,31,30,31,30,31])
+%!assert (eomday (1:3,1:3), [31,28,31])
+%!assert (eomday (1:2000,2)', datevec(datenum(1:2000,3,0))(:,3))
+%!assert ([1900:1999](find(eomday(1900:1999,2*ones(1,100))==29)), [1904,1908,1912,1916,1920,1924,1928,1932,1936,1940,1944,1948,1952,1956,1960,1964,1968,1972,1976,1980,1984,1988,1992,1996])
+%!assert (eomday ([2004;2005], [2;2]), [29;28])
+
+%% Test input validation
+%!error eomday ()
+%!error eomday (1)
+%!error eomday (1,2,3)
+
--- a/scripts/time/etime.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/etime.m	Thu Nov 10 13:35:08 2011 -0800
@@ -32,7 +32,7 @@
 ## @noindent
 ## will set the variable @code{elapsed_time} to the number of seconds since
 ## the variable @code{t0} was set.
-## @seealso{tic, toc, clock, cputime}
+## @seealso{tic, toc, clock, cputime, addtodate}
 ## @end deftypefn
 
 ## Author: jwe
@@ -50,14 +50,15 @@
 
 endfunction
 
-%!assert(etime([1900,12,31,23,59,59],[1901,1,1,0,0,0]),-1)
-%!assert(etime([1900,2,28,23,59,59],[1900,3,1,0,0,0]),-1)
-%!assert(etime([2000,2,28,23,59,59],[2000,3,1,0,0,0]),-86401)
-%!assert(etime([1996,2,28,23,59,59],[1996,3,1,0,0,0]),-86401)
+
+%!assert (etime ([1900,12,31,23,59,59],[1901,1,1,0,0,0]),-1)
+%!assert (etime ([1900,2,28,23,59,59],[1900,3,1,0,0,0]),-1)
+%!assert (etime ([2000,2,28,23,59,59],[2000,3,1,0,0,0]),-86401)
+%!assert (etime ([1996,2,28,23,59,59],[1996,3,1,0,0,0]),-86401)
 %!test
-%!  t1 = [1900,12,31,23,59,59; 1900,2,28,23,59,59];
-%!  t2 = [1901,1,1,0,0,0; 1900,3,1,0,0,0];
-%!  assert(etime(t2, t1), [1;1]);
+%! t1 = [1900,12,31,23,59,59; 1900,2,28,23,59,59];
+%! t2 = [1901,1,1,0,0,0; 1900,3,1,0,0,0];
+%! assert(etime(t2, t1), [1;1]);
 
 %!test
 %! t1 = [1993, 8, 20, 4, 56, 1];
@@ -66,10 +67,13 @@
 %! t4 = [1993, 8, 20, 4, 57, 1];
 %! t5 = [1993, 8, 20, 4, 56, 14];
 %!
-%! assert((etime (t2, t1) == 86400 && etime (t3, t1) == 3600
-%! && etime (t4, t1) == 60 && etime (t5, t1) == 13));
+%! assert (etime (t2, t1), 86400);
+%! assert (etime (t3, t1), 3600);
+%! assert (etime (t4, t1), 60);
+%! assert (etime (t5, t1), 13);
 
+%% Test input validation
 %!error etime ();
-
+%!error etime (1);
 %!error etime (1, 2, 3);
 
--- a/scripts/time/is_leap_year.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/is_leap_year.m	Thu Nov 10 13:35:08 2011 -0800
@@ -19,8 +19,8 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} is_leap_year ()
 ## @deftypefnx {Function File} {} is_leap_year (@var{year})
-## Return true if the given year is a leap year and false otherwise.  If no
-## year is provided, @code{is_leap_year} will use the current year.
+## Return true if @var{year} is a leap year and false otherwise.  If no
+## year is specified, @code{is_leap_year} uses the current year.
 ## For example:
 ##
 ## @example
@@ -29,6 +29,7 @@
 ##      @result{} 1
 ## @end group
 ## @end example
+## @seealso{weekday, eomday, calendar}
 ## @end deftypefn
 
 ## Author: jwe
@@ -41,17 +42,19 @@
 
   if (nargin == 0)
     t = clock ();
-    year = t (1);
+    year = t(1);
   endif
 
-  retval = ((rem (year, 4) == 0 & rem (year, 100) != 0) ...
-            | rem (year, 400) == 0);
+  retval = (rem (year, 4) == 0 & rem (year, 100) != 0) | (rem (year, 400) == 0);
 
 endfunction
 
-%!assert((is_leap_year (2000) == 1 && is_leap_year (1976) == 1
-%! && is_leap_year (1000) == 0 && is_leap_year (1800) == 0
-%! && is_leap_year (1600) == 1));
+
+%!assert (is_leap_year (2000), true)
+%!assert (is_leap_year (1976), true)
+%!assert (is_leap_year (1000), false)
+%!assert (is_leap_year (1800), false)
+%!assert (is_leap_year (1600), true)
 
 %!error is_leap_year (1, 2);
 
--- a/scripts/time/now.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/now.m	Thu Nov 10 13:35:08 2011 -0800
@@ -18,16 +18,14 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {t =} now ()
-## Return the current local time as the number of days since Jan 1, 0000.
-## By this reckoning, Jan 1, 1970 is day number 719529.
+## Return the current local date/time as a serial day number
+## (see @code{datenum}).
 ##
-## The integral part, @code{floor (now)} corresponds to 00:00:00 today.
+## The integral part, @code{floor (now)} corresponds to the number of days
+## between today and Jan 1, 0000.
 ##
 ## The fractional part, @code{rem (now, 1)} corresponds to the current
-## time on Jan 1, 0000.
-##
-## The returned value is also called a "serial date number"
-## (see @code{datenum}).
+## time.
 ## @seealso{clock, date, datenum}
 ## @end deftypefn
 
@@ -37,12 +35,12 @@
 
 function t = now ()
 
-  if (nargin == 0)
-    t = datenum (clock ());
-  else
+  if (nargin != 0)
     print_usage ();
   endif
 
+  t = datenum (clock ());
+
   ## The following doesn't work (e.g., one hour off on 2005-10-04):
   ##
   ##   seconds since 1970-1-1 corrected by seconds from GMT to local time
@@ -55,7 +53,9 @@
 
 endfunction
 
-%!error now (1);
+
 %!assert (isnumeric (now ()));
 %!assert (now () > 0);
 %!assert (now () <= now ());
+
+%!error now (1);
--- a/scripts/time/weekday.m	Thu Nov 10 02:50:51 2011 -0500
+++ b/scripts/time/weekday.m	Thu Nov 10 13:35:08 2011 -0800
@@ -19,49 +19,58 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {[@var{n}, @var{s}] =} weekday (@var{d})
 ## @deftypefnx {Function File} {[@var{n}, @var{s}] =} weekday (@var{d}, @var{format})
-## Return the day of week as a number in @var{n} and a string in @var{s},
-## for example @code{[1, "Sun"]}, @code{[2, "Mon"]}, @dots{}, or
-## @code{[7, "Sat"]}.
+## Return the day of the week as a number in @var{n} and as a string in @var{s}.
+## The days of the week are numbered 1--7 with the first day being Sunday.
 ##
 ## @var{d} is a serial date number or a date string.
 ##
-## If the string @var{format} is given and is @code{"long"}, @var{s} will
-## contain the full name of the weekday; otherwise (or if @var{format} is
-## @code{"short"}), @var{s} will contain the abbreviated name of the weekday.
-## @seealso{datenum, datevec, eomday}
+## If the string @var{format} is not present or is equal to "short" then
+## @var{s} will contain the abbreviated name of the weekday.  If @var{format}
+## is "long" then @var{s} will contain the full name.
+##
+## Table of return values based on @var{format}:
+##
+## @multitable @columnfractions .06 .13 .13
+## @headitem @var{n} @tab "short" @tab "long"
+## @item 1 @tab Sun @tab Sunday
+## @item 2 @tab Mon @tab Monday
+## @item 3 @tab Tue @tab Tuesday
+## @item 4 @tab Wed @tab Wednesday
+## @item 5 @tab Thu @tab Thursday
+## @item 6 @tab Fri @tab Friday
+## @item 7 @tab Sat @tab Saturday
+## @end multitable
+## 
+## @seealso{eomday, is_leap_year, calendar, datenum, datevec}
 ## @end deftypefn
 
 ## Author: pkienzle <pkienzle@users.sf.net>
 ## Created: 10 October 2001 (CVS)
 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
 
-function [d, s] = weekday (d, format)
+function [d, s] = weekday (d, format = "short")
 
   if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
 
-  if (nargin < 2)
-    format = "short";
-  endif
-
-  if (iscell (d) || isnumeric (d))
+  if (iscellstr (d) || isnumeric (d))
     endsize = size (d);
   elseif (ischar (d))
-    endsize = [size(d, 1), 1];
+    endsize = [rows(d), 1];
   endif
-  if (ischar (d) || iscell (d))
+  if (ischar (d) || iscellstr (d))
     ## Make sure the date is numeric
     d = datenum (d);
   endif
   ## Find the offset from a known Sunday (2008-Jan-6), mod 7.
-  d = floor (reshape (mod(d - 733048, 7), endsize));
+  d = floor (reshape (mod (d - 733048, 7), endsize));
   ## Make Saturdays a 7 and not a 0.
   d(!d) = 7;
 
-  if (nargout > 1)
+  if (isargout (2))
     if (strcmpi (format, "long"))
-      names = {"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" \
+      names = {"Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" ...
                "Friday" "Saturday"};
     else
       names = {"Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"};
@@ -71,41 +80,45 @@
 
 endfunction
 
+
+%!demo
+%! ## Current weekday
+%! [n, s] = weekday (now ())
+%!demo
+%! ## Weekday from datenum input
+%! [n, s] = weekday (728647)
+%!demo
+%! ## Weekday of new millennium from datestr input
+%! [n, s] = weekday ('1-Jan-2000')
+
 # tests
-%!assert(weekday(728647),2)
+%!assert (weekday (728647), 2)
 ## Test vector inputs for both directions
-%!assert(weekday([728647 728648]), [2 3])
-%!assert(weekday([728647;728648]), [2;3])
+%!assert (weekday ([728647 728648]), [2 3])
+%!assert (weekday ([728647;728648]), [2;3])
 ## Test a full week before our reference day
-%!assert(weekday('19-Dec-1994'),2)
-%!assert(weekday('20-Dec-1994'),3)
-%!assert(weekday('21-Dec-1994'),4)
-%!assert(weekday('22-Dec-1994'),5)
-%!assert(weekday('23-Dec-1994'),6)
-%!assert(weekday('24-Dec-1994'),7)
-%!assert(weekday('25-Dec-1994'),1)
+%!assert (weekday ("19-Dec-1994"), 2)
+%!assert (weekday ("20-Dec-1994"), 3)
+%!assert (weekday ("21-Dec-1994"), 4)
+%!assert (weekday ("22-Dec-1994"), 5)
+%!assert (weekday ("23-Dec-1994"), 6)
+%!assert (weekday ("24-Dec-1994"), 7)
+%!assert (weekday ("25-Dec-1994"), 1)
 ## Test our reference day
-%!assert(weekday('6-Jan-2008'),1)
+%!assert (weekday ("6-Jan-2008"), 1)
 ## Test a full week after our reference day
-%!assert(weekday('1-Feb-2008'),6)
-%!assert(weekday('2-Feb-2008'),7)
-%!assert(weekday('3-Feb-2008'),1)
-%!assert(weekday('4-Feb-2008'),2)
-%!assert(weekday('5-Feb-2008'),3)
-%!assert(weekday('6-Feb-2008'),4)
-%!assert(weekday('7-Feb-2008'),5)
+%!assert (weekday ("1-Feb-2008"), 6)
+%!assert (weekday ("2-Feb-2008"), 7)
+%!assert (weekday ("3-Feb-2008"), 1)
+%!assert (weekday ("4-Feb-2008"), 2)
+%!assert (weekday ("5-Feb-2008"), 3)
+%!assert (weekday ("6-Feb-2008"), 4)
+%!assert (weekday ("7-Feb-2008"), 5)
 ## Test fractional dates
-%!assert(weekday(728647.1),2)
+%!assert (weekday (728647.1), 2)
 ## Test "long" option
 %!test
-%! [a, b] = weekday ("25-Dec-1994", "long");
-%! assert (a, 1);
-%! assert (b, "Sunday");
+%! [n, s] = weekday ("25-Dec-1994", "long");
+%! assert (n, 1);
+%! assert (s, "Sunday");
 
-# demos
-%!demo
-%! [n, s] = weekday (now ())
-%!demo
-%! [n, s] = weekday (728647)
-%!demo
-%! [n, s] = weekday ('19-Dec-1994')