Mercurial > hg > octave-nkf
annotate scripts/time/now.m @ 12836:e9b4de878a9c
codesprint: new tests for now function
* now.m: New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 16 Jul 2011 17:45:54 -0400 |
parents | d0b799dafede |
children | 4dfc13ca35b9 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2000-2011 Paul Kienzle |
5687 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5687 | 9 ## |
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. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5687 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {t =} now () | |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## Return the current local time as the number of days since Jan 1, 0000. |
5687 | 22 ## By this reckoning, Jan 1, 1970 is day number 719529. |
23 ## | |
24 ## The integral part, @code{floor (now)} corresponds to 00:00:00 today. | |
25 ## | |
26 ## The fractional part, @code{rem (now, 1)} corresponds to the current | |
27 ## time on Jan 1, 0000. | |
28 ## | |
29 ## The returned value is also called a "serial date number" | |
30 ## (see @code{datenum}). | |
31 ## @seealso{clock, date, datenum} | |
32 ## @end deftypefn | |
33 | |
34 ## Author: pkienzle <pkienzle@users.sf.net> | |
35 ## Created: 10 October 2001 (CVS) | |
36 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> | |
37 | |
38 function t = now () | |
39 | |
12836
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
40 if (nargin == 0) |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
41 t = datenum (clock ()); |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
42 else |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
43 print_usage (); |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
44 endif |
5687 | 45 |
46 ## The following doesn't work (e.g., one hour off on 2005-10-04): | |
47 ## | |
48 ## seconds since 1970-1-1 corrected by seconds from GMT to local time | |
49 ## divided by 86400 sec/day plus day num for 1970-1-1 | |
50 ## t = (time - mktime(gmtime(0)))/86400 + 719529; | |
51 ## | |
52 ## mktime(gmtime(0)) does indeed return the offset from Greenwich to the | |
53 ## local time zone, but we need to account for daylight savings time | |
54 ## changing by an hour the offset from CUT for part of the year. | |
55 | |
56 endfunction | |
12836
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
57 |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
58 %!error now (1); |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
59 %!assert (isnumeric (now ()); |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
60 %!assert (now () > 0); |
e9b4de878a9c
codesprint: new tests for now function
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
61 %!assert (now () >= now ()); |