Mercurial > hg > octave-nkf
annotate scripts/time/clock.m @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | d490ca8ab1a5 |
children | f3d52523cde1 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13856
diff
changeset
|
1 ## Copyright (C) 1995-2012 John W. Eaton |
2313 | 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. | |
2313 | 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/>. | |
1183 | 18 |
3301 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} clock () | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## Return the current local date and time as a date vector. The date vector |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 ## contains the following fields: current year, month (1-12), day (1-31), |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 ## hour (0-23), minute (0-59), and second (0-61). The seconds field has |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
24 ## a fractional part after the decimal point for extended accuracy. |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
25 ## |
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
26 ## For example: |
3426 | 27 ## |
3301 | 28 ## @example |
29 ## @group | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
30 ## fix (clock ()) |
3301 | 31 ## @result{} [ 1993, 8, 20, 4, 56, 1 ] |
32 ## @end group | |
33 ## @end example | |
3426 | 34 ## |
3301 | 35 ## The function clock is more accurate on systems that have the |
36 ## @code{gettimeofday} function. | |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
37 ## @seealso{now, date, datevec} |
3301 | 38 ## @end deftypefn |
1183 | 39 |
2314 | 40 ## Author: jwe |
41 | |
2311 | 42 function retval = clock () |
1183 | 43 |
44 tm = localtime (time ()); | |
45 | |
46 retval = zeros (1, 6); | |
47 | |
1374 | 48 retval(1) = tm.year + 1900; |
49 retval(2) = tm.mon + 1; | |
50 retval(3) = tm.mday; | |
51 retval(4) = tm.hour; | |
52 retval(5) = tm.min; | |
53 retval(6) = tm.sec + tm.usec / 1e6; | |
1183 | 54 |
55 endfunction | |
7411 | 56 |
57 %!test | |
58 %! t1 = clock; | |
59 %! t2 = str2num (strftime ("[%Y, %m, %d, %H, %M, %S]", localtime (time ()))); | |
60 %! assert(etime (t1, t2) < 1); | |
61 |