comparison m-toolbox/classes/@time/datenum.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % DATENUM Converts a time object into MATLAB serial date representation
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % DESCRIPTION: Converts a time object into MATLAB serial date number. A serial
4 % date number of 1 corresponds to Jan-01-0000. The year 0000 is merely a
5 % reference point and is not intended to be interpreted as a real year.
6 %
7 % NOTE: time objects formatting routines use the timezone specified in the LTPDA
8 % toolbox preferences, while MATLAB time routines always work in the local time
9 % zone, as specified by the operating system. This conversion routine is built
10 % so that the time string representation obtained by time.format() and the one
11 % obtained from datestr(datenum(time)) are equivalent:
12 %
13 % >> t1 = time();
14 % >> datestr(datenum(t1)) === t1.format('dd-mmm-yyyy HH:MM:SS')
15 %
16 % However, except in the cases where the timezone is set to UTC in the LTPDA
17 % toolbox preferences, this implies that:
18 %
19 % >> datenum(time()) ~= now()
20 %
21 % VERSION: $Id: datenum.m,v 1.2 2010/07/29 18:07:55 nicolodi Exp $
22 %
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25 function num = datenum(obj)
26
27 % number of seconds since 1970-01-01 00:00:00.000 UTC
28 num = double(obj);
29
30 % take care of timezone offset
31 num = num + time.timezone.getOffset(num * 1000)/1000;
32
33 % divide by 60*60*24 to convert into days and add offset computed in local time
34 num = num / 86400 + datenummx(1970,01,01,00,00,00);
35
36 % NOTE: the MEX function datenummx() is used instead of the datenum() MATLAB
37 % function to save time of the expensive input arguments checks performed by
38 % the later
39
40 end
41