diff 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
line wrap: on
line diff
--- a/scripts/time/datevec.m	Wed Jun 14 18:18:51 2006 +0000
+++ b/scripts/time/datevec.m	Fri Jun 16 05:01:39 2006 +0000
@@ -156,7 +156,10 @@
     ## datenum format.
 
     fracd = date - floor (date);
-    srnd = 10 .^ floor (log10 (365.25*y));
+    ## Special case for total days <= 0.
+    tmpd = abs (365.25*y);
+    tmpd(tmpd == 0) = 1;
+    srnd = 10 .^ floor (log10 (tmpd));
     s = round (86400*fracd.*srnd) ./ srnd;
     h = floor (s / 3600);
     s = s - 3600 * h;
@@ -300,7 +303,7 @@
 %!assert(all(datenum(datevec([-1e4:1e4]))==[-1e4:1e4]'))
 %!test
 %! t = linspace (-2e5, 2e5, 10993);
-%! assert (all (datenum (datevec (t)) == t'));
+%! assert (all (abs (datenum (datevec (t)) - t') < 1e-5));
 # demos
 %!demo
 %! datevec (now ())