comparison scripts/time/datevec.m @ 5860:b645066d40ad

[project @ 2006-06-16 05:01:38 by jwe]
author jwe
date Fri, 16 Jun 2006 05:01:39 +0000
parents ba0bea22167b
children b6ef36e92701
comparison
equal deleted inserted replaced
5859:ba0bea22167b 5860:b645066d40ad
154 154
155 ## Convert hour-minute-seconds. Attempt to account for precision of 155 ## Convert hour-minute-seconds. Attempt to account for precision of
156 ## datenum format. 156 ## datenum format.
157 157
158 fracd = date - floor (date); 158 fracd = date - floor (date);
159 srnd = 10 .^ floor (log10 (365.25*y)); 159 ## Special case for total days <= 0.
160 tmpd = abs (365.25*y);
161 tmpd(tmpd == 0) = 1;
162 srnd = 10 .^ floor (log10 (tmpd));
160 s = round (86400*fracd.*srnd) ./ srnd; 163 s = round (86400*fracd.*srnd) ./ srnd;
161 h = floor (s / 3600); 164 h = floor (s / 3600);
162 s = s - 3600 * h; 165 s = s - 3600 * h;
163 mi = floor (s / 60); 166 mi = floor (s / 60);
164 s = s - 60 * mi; 167 s = s - 60 * mi;
298 %!assert(datevec("03/13/1962"),[1962,3,13,0,0,0]); 301 %!assert(datevec("03/13/1962"),[1962,3,13,0,0,0]);
299 # other tests 302 # other tests
300 %!assert(all(datenum(datevec([-1e4:1e4]))==[-1e4:1e4]')) 303 %!assert(all(datenum(datevec([-1e4:1e4]))==[-1e4:1e4]'))
301 %!test 304 %!test
302 %! t = linspace (-2e5, 2e5, 10993); 305 %! t = linspace (-2e5, 2e5, 10993);
303 %! assert (all (datenum (datevec (t)) == t')); 306 %! assert (all (abs (datenum (datevec (t)) - t') < 1e-5));
304 # demos 307 # demos
305 %!demo 308 %!demo
306 %! datevec (now ()) 309 %! datevec (now ())