[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug in datestr.m
From: |
Bill Denney |
Subject: |
Bug in datestr.m |
Date: |
Wed, 13 Feb 2008 22:53:50 -0500 |
User-agent: |
Thunderbird 2.0.0.9 (Windows/20071031) |
datestr.m will give errors if you happen to give a vector or matrix of
datenums that happens to have 6 columns. The attached patch fixes this
and adds a test.
I put the changelog in the changeset. Is that the correct way to do it now?
Have a good day,
Bill
# HG changeset patch
# User address@hidden
# Date 1202960784 18000
# Node ID 50626ab21494f69e82d811a9ff1552f3b1f1af44
# Parent 8d6ab12f8fda3d17be69c515a726716af0c88ca7
datestr.m: fix 6 datenum vector bug
diff -r 8d6ab12f8fda -r 50626ab21494 scripts/time/datestr.m
--- a/scripts/time/datestr.m Sat Feb 09 03:37:39 2008 -0500
+++ b/scripts/time/datestr.m Wed Feb 13 22:46:24 2008 -0500
@@ -203,7 +203,20 @@ function retval = datestr (date, f, p)
if (iscell (date) || columns (date) != 6)
v = datevec (date, p);
else
- v = date;
+ v = [];
+ if columns (date) == 6
+ ## make sure that the input really is a datevec
+ maxdatevec = [inf 12 31 23 59 60];
+ for i = 1:numel (maxdatevec)
+ if any (date(:,i) > maxdatevec(i))
+ v = datevec (date, p);
+ break;
+ endif
+ endfor
+ endif
+ if isempty (v)
+ v = date;
+ endif
endif
for i = 1:(rows (v))
@@ -328,6 +341,9 @@ endfunction
%!assert(datestr(testtime,29),"20051218");
%!assert(datestr(testtime,30),"20051218T023317");
%!assert(datestr(testtime,31),"2005-12-18 02:33:17");
+## avoid the bug where someone happens to give a vector of datenums that
+## happens to be 6 wide
+%!assert(datestr(733452.933:733457.933), ["14-Feb-2008 22:23:31";"15-Feb-2008
22:23:31";"16-Feb-2008 22:23:31";"17-Feb-2008 22:23:31";"18-Feb-2008
22:23:31";"19-Feb-2008 22:23:31"])
# demos
%!demo
%! datestr (now ())
- Bug in datestr.m,
Bill Denney <=