]> Creatis software - CreaPhase.git/blob - octave_packages/m/time/clock.m
update packages
[CreaPhase.git] / octave_packages / m / time / clock.m
1 ## Copyright (C) 1995-2012 John W. Eaton
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} clock ()
21 ## Return the current local date and time as a date vector.  The date vector
22 ## contains the following fields: current year, month (1-12), day (1-31),
23 ## hour (0-23), minute (0-59), and second (0-61).  The seconds field has
24 ## a fractional part after the decimal point for extended accuracy.
25 ##
26 ## For example:
27 ##
28 ## @example
29 ## @group
30 ## fix (clock ())
31 ##      @result{} [ 1993, 8, 20, 4, 56, 1 ]
32 ## @end group
33 ## @end example
34 ##
35 ## The function clock is more accurate on systems that have the
36 ## @code{gettimeofday} function.
37 ## @seealso{now, date, datevec}
38 ## @end deftypefn
39
40 ## Author: jwe
41
42 function retval = clock ()
43
44   tm = localtime (time ());
45
46   retval = zeros (1, 6);
47
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;
54
55 endfunction
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