comparison scripts/time/now.m @ 5687:a2902024bc4e

[project @ 2006-03-16 20:22:40 by jwe]
author jwe
date Thu, 16 Mar 2006 20:22:41 +0000
parents
children 93c65f2a5668
comparison
equal deleted inserted replaced
5686:e7790bb14cfc 5687:a2902024bc4e
1 ## Copyright (C) 2000, 2001, 2003, 2005 Paul Kienzle
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 2, or (at your option)
8 ## 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, write to the Free
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA.
19
20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {t =} now ()
22 ## Returns the current local time as the number of days since Jan 1, 0000.
23 ## By this reckoning, Jan 1, 1970 is day number 719529.
24 ##
25 ## The integral part, @code{floor (now)} corresponds to 00:00:00 today.
26 ##
27 ## The fractional part, @code{rem (now, 1)} corresponds to the current
28 ## time on Jan 1, 0000.
29 ##
30 ## The returned value is also called a "serial date number"
31 ## (see @code{datenum}).
32 ## @seealso{clock, date, datenum}
33 ## @end deftypefn
34
35 ## Author: pkienzle <pkienzle@users.sf.net>
36 ## Created: 10 October 2001 (CVS)
37 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
38
39 function t = now ()
40
41 t = datenum (clock ());
42
43 ## The following doesn't work (e.g., one hour off on 2005-10-04):
44 ##
45 ## seconds since 1970-1-1 corrected by seconds from GMT to local time
46 ## divided by 86400 sec/day plus day num for 1970-1-1
47 ## t = (time - mktime(gmtime(0)))/86400 + 719529;
48 ##
49 ## mktime(gmtime(0)) does indeed return the offset from Greenwich to the
50 ## local time zone, but we need to account for daylight savings time
51 ## changing by an hour the offset from CUT for part of the year.
52
53 endfunction