Mercurial > hg > octave-nkf
comparison libinterp/corefcn/time.cc @ 19334:b8bd0b55af45
codesprint: Add tests to time handling functions
* time.cc: Add tests and input validation for time, mktime, strftime, and
strptime.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Sun, 21 Sep 2014 16:08:25 -0400 |
parents | 175b392e91fe |
children | 03067dab10ca |
comparison
equal
deleted
inserted
replaced
19333:25ab600d16fd | 19334:b8bd0b55af45 |
---|---|
121 return retval; | 121 return retval; |
122 } | 122 } |
123 | 123 |
124 /* | 124 /* |
125 %!assert (time () > 0) | 125 %!assert (time () > 0) |
126 | |
127 %!error time (1) | |
126 */ | 128 */ |
127 | 129 |
128 DEFUN (gmtime, args, , | 130 DEFUN (gmtime, args, , |
129 "-*- texinfo -*-\n\ | 131 "-*- texinfo -*-\n\ |
130 @deftypefn {Built-in Function} {@var{tm_struct} =} gmtime (@var{t})\n\ | 132 @deftypefn {Built-in Function} {@var{tm_struct} =} gmtime (@var{t})\n\ |
297 %!assert (datestr (datenum (1969, 1, 1), 0), "01-Jan-1969 00:00:00") | 299 %!assert (datestr (datenum (1969, 1, 1), 0), "01-Jan-1969 00:00:00") |
298 %!assert (datestr (datenum (1901, 1, 1), 0), "01-Jan-1901 00:00:00") | 300 %!assert (datestr (datenum (1901, 1, 1), 0), "01-Jan-1901 00:00:00") |
299 %!assert (datestr (datenum (1795, 1, 1), 0), "01-Jan-1795 00:00:00") | 301 %!assert (datestr (datenum (1795, 1, 1), 0), "01-Jan-1795 00:00:00") |
300 | 302 |
301 %!error mktime () | 303 %!error mktime () |
304 %!error mktime (1) | |
302 %!error mktime (1, 2, 3) | 305 %!error mktime (1, 2, 3) |
306 %!error mktime (struct ("year", "foo")) | |
303 */ | 307 */ |
304 | 308 |
305 DEFUN (strftime, args, , | 309 DEFUN (strftime, args, , |
306 "-*- texinfo -*-\n\ | 310 "-*- texinfo -*-\n\ |
307 @deftypefn {Built-in Function} {} strftime (@var{fmt}, @var{tm_struct})\n\ | 311 @deftypefn {Built-in Function} {} strftime (@var{fmt}, @var{tm_struct})\n\ |
492 %!assert (ischar (strftime ("%X%Z%z%a%A%b%B", localtime (time ())))); | 496 %!assert (ischar (strftime ("%X%Z%z%a%A%b%B", localtime (time ())))); |
493 %!assert (ischar (strftime ("%c%C%d%e%D%h%j", localtime (time ())))); | 497 %!assert (ischar (strftime ("%c%C%d%e%D%h%j", localtime (time ())))); |
494 %!assert (ischar (strftime ("%m%U%w%W%x%y%Y", localtime (time ())))); | 498 %!assert (ischar (strftime ("%m%U%w%W%x%y%Y", localtime (time ())))); |
495 | 499 |
496 %!error strftime () | 500 %!error strftime () |
501 %!error strftime ("foo", 1) | |
502 %!error strftime ("foo", struct ("year", "foo")) | |
497 %!error strftime ("foo", localtime (time ()), 1) | 503 %!error strftime ("foo", localtime (time ()), 1) |
498 */ | 504 */ |
499 | 505 |
500 DEFUN (strptime, args, , | 506 DEFUN (strptime, args, , |
501 "-*- texinfo -*-\n\ | 507 "-*- texinfo -*-\n\ |
535 else | 541 else |
536 print_usage (); | 542 print_usage (); |
537 | 543 |
538 return retval; | 544 return retval; |
539 } | 545 } |
546 | |
547 /* | |
548 %!test | |
549 %! fmt = "%Y-%m-%d %H:%M:%S"; | |
550 %! s = strftime (fmt, localtime (time ())); | |
551 %! ts = strptime (s, fmt); | |
552 %! assert (isstruct (ts)); | |
553 %! assert (isfield (ts, "usec")); | |
554 %! assert (isfield (ts, "year")); | |
555 %! assert (isfield (ts, "mon")); | |
556 %! assert (isfield (ts, "mday")); | |
557 %! assert (isfield (ts, "sec")); | |
558 %! assert (isfield (ts, "min")); | |
559 %! assert (isfield (ts, "wday")); | |
560 %! assert (isfield (ts, "hour")); | |
561 %! assert (isfield (ts, "isdst")); | |
562 %! assert (isfield (ts, "yday")); | |
563 | |
564 %!error strptime () | |
565 */ |