comparison scripts/time/datevec.m @ 19867:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children 2645f9ef8c88
comparison
equal deleted inserted replaced
19866:a1acca0c2216 19867:9fc020886ae9
123 123
124 if (f == -1) 124 if (f == -1)
125 for k = 1:nd 125 for k = 1:nd
126 found = false; 126 found = false;
127 for l = 1:nfmt 127 for l = 1:nfmt
128 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (std_formats{l}); 128 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = ...
129 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs); 129 __date_vfmt2sfmt__ (std_formats{l});
130 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = ...
131 __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs);
130 if (found) 132 if (found)
131 break; 133 break;
132 endif 134 endif
133 endfor 135 endfor
134 if (! found) 136 if (! found)
137 endfor 139 endfor
138 else 140 else
139 ## Decipher the format string just once for speed. 141 ## Decipher the format string just once for speed.
140 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (f); 142 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (f);
141 for k = 1:nd 143 for k = 1:nd
142 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs); 144 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = ...
145 __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs);
143 if (! found) 146 if (! found)
144 error ("datevec: DATE not parsed correctly with given format"); 147 error ("datevec: DATE not parsed correctly with given format");
145 endif 148 endif
146 endfor 149 endfor
147 endif 150 endif
333 %! t = linspace (-2e5, 2e5, 10993); 336 %! t = linspace (-2e5, 2e5, 10993);
334 %! assert (all (abs (datenum (datevec (t)) - t') < 1e-5)); 337 %! assert (all (abs (datenum (datevec (t)) - t') < 1e-5));
335 %!assert (double (datevec (int64 (datenum ([2014 6 1])))), datevec (datenum ([2014 6 1]))) 338 %!assert (double (datevec (int64 (datenum ([2014 6 1])))), datevec (datenum ([2014 6 1])))
336 %!assert (double (datevec (int64 (datenum ([2014 6 18])))), datevec (datenum ([2014 6 18]))) 339 %!assert (double (datevec (int64 (datenum ([2014 6 18])))), datevec (datenum ([2014 6 18])))
337 340
338 %% Test input validation 341 ## Test input validation
339 %!error datevec () 342 %!error datevec ()
340 %!error datevec (1,2,3,4) 343 %!error datevec (1,2,3,4)
341 %!error <none of the standard formats match> datevec ("foobar") 344 %!error <none of the standard formats match> datevec ("foobar")
342 %!error <DATE not parsed correctly with given format> datevec ("foobar", "%d") 345 %!error <DATE not parsed correctly with given format> datevec ("foobar", "%d")
343 346