Mercurial > hg > octave-nkf
comparison scripts/time/datenum.m @ 14737:94a8366f9f89
datenum.m: Ensure all inputs are of class double (Bug #36587).
* datenum.m: Ensure all inputs are of class double. Add tests for new behavior.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 05 Jun 2012 16:11:25 -0700 |
parents | 4f458e882516 |
children | ec924357b375 |
comparison
equal
deleted
inserted
replaced
14735:295bd3efc065 | 14737:94a8366f9f89 |
---|---|
107 month = year(:,2); | 107 month = year(:,2); |
108 year = year(:,1); | 108 year = year(:,1); |
109 endif | 109 endif |
110 endif | 110 endif |
111 | 111 |
112 month(month<1) = 1; ## For compatibility. Otherwise allow negative months. | 112 if (! (isa (year, "double") && isa (month, "double") && isa (day, "double") && |
113 isa (hour, "double") && isa (minute, "double") && isa (second, "double"))) | |
114 error ("datenum: all inputs must be of class double"); | |
115 endif | |
116 | |
117 month(month<1) = 1; # For compatibility. Otherwise allow negative months. | |
113 | 118 |
114 ## Treat fractional months, by converting the fraction to days | 119 ## Treat fractional months, by converting the fraction to days |
115 if (floor (month) != month) | 120 if (floor (month) != month) |
116 fracmonth = month - floor (month); | 121 fracmonth = month - floor (month); |
117 month = floor (month); | 122 month = floor (month); |
193 %!assert (datenum ({"5/19/2001", "6/6/1944"}), [730990; 710189]) | 198 %!assert (datenum ({"5/19/2001", "6/6/1944"}), [730990; 710189]) |
194 | 199 |
195 %% Test input validation | 200 %% Test input validation |
196 %!error datenum () | 201 %!error datenum () |
197 %!error datenum (1,2,3,4,5,6,7) | 202 %!error datenum (1,2,3,4,5,6,7) |
198 %!error datenum ([1, 2]) | 203 %!error <expected date vector containing> datenum ([1, 2]) |
199 %!error datenum ([1,2,3,4,5,6,7]) | 204 %!error <expected date vector containing> datenum ([1,2,3,4,5,6,7]) |
205 %!error <all inputs must be of class double> datenum (int32 (2000), int32 (1), int32 (1)) |