Mercurial > octave
annotate scripts/time/datevec.m @ 30649:744778e9210b
datevec.m: Tweak BIST test in c7a515aa767e.
* datevec.m: Tweak BIST test to correctly test issue.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 14 Jan 2022 12:23:29 -0800 |
parents | c7a515aa767e |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30379
diff
changeset
|
3 ## Copyright (C) 2000-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
5687 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23967
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
5687 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23967
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
13 ## (at your option) any later version. |
5687 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
18 ## GNU General Public License for more details. |
5687 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23967
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
5687 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20715
diff
changeset
|
27 ## @deftypefn {} {@var{v} =} datevec (@var{date}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20715
diff
changeset
|
28 ## @deftypefnx {} {@var{v} =} datevec (@var{date}, @var{f}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20715
diff
changeset
|
29 ## @deftypefnx {} {@var{v} =} datevec (@var{date}, @var{p}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20715
diff
changeset
|
30 ## @deftypefnx {} {@var{v} =} datevec (@var{date}, @var{f}, @var{p}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20715
diff
changeset
|
31 ## @deftypefnx {} {[@var{y}, @var{m}, @var{d}, @var{h}, @var{mi}, @var{s}] =} datevec (@dots{}) |
28958
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
32 ## Convert a serial date number (@pxref{XREFdatenum,,@code{datenum}}) or date |
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
33 ## string (@pxref{XREFdatestr,,@code{datestr}}) into a date vector. |
5687 | 34 ## |
35 ## A date vector is a row vector with six members, representing the year, | |
36 ## month, day, hour, minute, and seconds respectively. | |
37 ## | |
38 ## @var{f} is the format string used to interpret date strings | |
28958
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
39 ## (@pxref{XREFdatestr,,@code{datestr}}). If @var{date} is a string, but no |
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
40 ## format is specified, then a relatively slow search is performed through |
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
41 ## various formats. It is always preferable to specify the format string |
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
42 ## @var{f} if it is known. Formats which do not specify a particular time |
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
43 ## component will have the value set to zero. Formats which do not specify a |
6fd6ad758b10
doc: Use @xref, @pxref rather than "see @code{}" in TexInfo.
Rik <rik@octave.org>
parents:
28896
diff
changeset
|
44 ## date will default to January 1st of the current year. |
5687 | 45 ## |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
46 ## @var{p} is the year at the start of the century to which two-digit years |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
47 ## will be referenced. If not specified, it defaults to the current year minus |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
48 ## 50. |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13848
diff
changeset
|
49 ## @seealso{datenum, datestr, clock, now, date} |
5687 | 50 ## @end deftypefn |
51 | |
52 ## Algorithm: Peter Baum (http://vsg.cape.com/~pbaum/date/date0.htm) | |
53 | |
54 ## The function __date_str2vec__ is based on datesplit by Bill Denney. | |
55 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
56 function [y, m, d, h, mi, s] = datevec (date, f = [], p = []) |
5687 | 57 |
58 persistent std_formats nfmt; | |
59 | |
60 if (isempty (std_formats)) | |
61 std_formats = cell (); | |
62 nfmt = 0; | |
14743
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
63 ## These formats are specified by Matlab documentation to be parsed |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
64 ## The '# XX' refers to the datestr numerical format code |
5687 | 65 std_formats{++nfmt} = "dd-mmm-yyyy HH:MM:SS"; # 0 |
66 std_formats{++nfmt} = "dd-mmm-yyyy"; # 1 | |
67 std_formats{++nfmt} = "mm/dd/yy"; # 2 | |
68 std_formats{++nfmt} = "mm/dd"; # 6 | |
69 std_formats{++nfmt} = "HH:MM:SS"; # 13 | |
70 std_formats{++nfmt} = "HH:MM:SS PM"; # 14 | |
71 std_formats{++nfmt} = "HH:MM"; # 15 | |
72 std_formats{++nfmt} = "HH:MM PM"; # 16 | |
73 std_formats{++nfmt} = "mm/dd/yyyy"; # 23 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
74 |
14743
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
75 ## These formats are undocumented but parsed by Matlab |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
76 std_formats{++nfmt} = "mmmyy"; # 12 |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
77 std_formats{++nfmt} = "mmm.dd,yyyy HH:MM:SS"; # 21 |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
78 std_formats{++nfmt} = "mmm.dd,yyyy"; # 22 |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
79 std_formats{++nfmt} = "yyyy/mm/dd"; # 26 |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
80 std_formats{++nfmt} = "yyyy-mm-dd"; # 29 |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
81 std_formats{++nfmt} = "yyyy-mm-dd HH:MM:SS"; # 31 |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
82 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
83 ## These are other formats that Octave tries |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
84 std_formats{++nfmt} = "mmm-dd-yyyy HH:MM:SS"; |
6044 | 85 std_formats{++nfmt} = "mmm-dd-yyyy"; |
86 std_formats{++nfmt} = "dd mmm yyyy HH:MM:SS"; | |
87 std_formats{++nfmt} = "dd mmm yyyy"; | |
88 std_formats{++nfmt} = "mmm dd yyyy HH:MM:SS"; | |
89 std_formats{++nfmt} = "mmm dd yyyy"; | |
90 std_formats{++nfmt} = "dd.mmm.yyyy HH:MM:SS"; | |
91 std_formats{++nfmt} = "dd.mmm.yyyy"; | |
92 std_formats{++nfmt} = "mmm.dd.yyyy HH:MM:SS"; | |
93 std_formats{++nfmt} = "mmm.dd.yyyy"; | |
5687 | 94 std_formats{++nfmt} = "mm/dd/yyyy HH:MM"; |
95 endif | |
96 | |
28789
28de41192f3c
Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents:
27984
diff
changeset
|
97 if (nargin < 1) |
6046 | 98 print_usage (); |
5687 | 99 endif |
100 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
101 if (ischar (date)) |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
102 date = cellstr (date); |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
103 endif |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
104 |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
105 if (isnumeric (f)) |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
106 p = f; |
5687 | 107 f = []; |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
108 endif |
5687 | 109 |
110 if (isempty (f)) | |
111 f = -1; | |
112 endif | |
113 | |
114 if (isempty (p)) | |
11400 | 115 p = (localtime (time ())).year + 1900 - 50; |
5687 | 116 endif |
117 | |
18747
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
118 do_resize = false; |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
119 |
5687 | 120 if (iscell (date)) |
121 | |
122 nd = numel (date); | |
123 | |
124 y = m = d = h = mi = s = zeros (nd, 1); | |
125 | |
126 if (f == -1) | |
127 for k = 1:nd | |
128 found = false; | |
129 for l = 1:nfmt | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
130 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
131 __date_vfmt2sfmt__ (std_formats{l}); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
132 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
133 __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs); |
5687 | 134 if (found) |
135 break; | |
136 endif | |
137 endfor | |
138 if (! found) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11400
diff
changeset
|
139 error ("datevec: none of the standard formats match the DATE string"); |
5687 | 140 endif |
141 endfor | |
142 else | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
143 ## Decipher the format string just once for speed. |
8411
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
144 [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (f); |
5687 | 145 for k = 1:nd |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
146 [found y(k) m(k) d(k) h(k) mi(k) s(k)] = ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
147 __date_str2vec__ (date{k}, p, f, rY, ry, fy, fm, fd, fh, fmi, fs); |
5687 | 148 if (! found) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11400
diff
changeset
|
149 error ("datevec: DATE not parsed correctly with given format"); |
5687 | 150 endif |
151 endfor | |
152 endif | |
153 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
154 else # datenum input |
5687 | 155 |
18749
38925538ec14
datevec.m: Change isrow to iscolumn in cset 9eb72fa5f8b5.
Rik <rik@octave.org>
parents:
18747
diff
changeset
|
156 if (! iscolumn (date)) |
18747
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
157 date_sz = size (date); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
158 do_resize = true; |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
159 endif |
5687 | 160 date = date(:); |
161 | |
162 ## Move day 0 from midnight -0001-12-31 to midnight 0000-3-1 | |
19384
7d272300a880
datevec.m: Fix negative number outputs with integer (non-float) inputs (bug #43753).
Nir Krakauer <nkrakauer@ccny.cuny.edu>
parents:
17744
diff
changeset
|
163 z = double (floor (date) - 60); |
5687 | 164 ## Calculate number of centuries; K1 = 0.25 is to avoid rounding problems. |
165 a = floor ((z - 0.25) / 36524.25); | |
166 ## Days within century; K2 = 0.25 is to avoid rounding problems. | |
167 b = z - 0.25 + a - floor (a / 4); | |
168 ## Calculate the year (year starts on March 1). | |
169 y = floor (b / 365.25); | |
170 ## Calculate day in year. | |
171 c = fix (b - floor (365.25 * y)) + 1; | |
172 ## Calculate month in year. | |
173 m = fix ((5 * c + 456) / 153); | |
174 d = c - fix ((153 * m - 457) / 5); | |
175 ## Move to Jan 1 as start of year. | |
176 ++y(m > 12); | |
177 m(m > 12) -= 12; | |
178 | |
5859 | 179 ## Convert hour-minute-seconds. Attempt to account for precision of |
180 ## datenum format. | |
181 | |
182 fracd = date - floor (date); | |
5873 | 183 tmps = abs (eps*86400*date); |
184 tmps(tmps == 0) = 1; | |
185 srnd = 2 .^ floor (- log2 (tmps)); | |
186 s = round (86400 * fracd .* srnd) ./ srnd; | |
5687 | 187 h = floor (s / 3600); |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
188 s -= 3600 * h; |
5687 | 189 mi = floor (s / 60); |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
190 s -= 60 * mi; |
5687 | 191 |
192 endif | |
193 | |
194 if (nargout <= 1) | |
5873 | 195 y = [y, m, d, h, mi, s]; |
18747
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
196 elseif (do_resize) |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
197 y = reshape (y, date_sz); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
198 m = reshape (m, date_sz); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
199 d = reshape (d, date_sz); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
200 h = reshape (h, date_sz); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
201 mi = reshape (mi, date_sz); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
202 s = reshape (s, date_sz); |
5687 | 203 endif |
204 | |
11086
af03ff97df7b
datevec.m: use endfunction to mark end of primary function and subfunctions
John W. Eaton <jwe@octave.org>
parents:
10793
diff
changeset
|
205 endfunction |
5687 | 206 |
8411
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
207 function [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (f) |
30379
363fb10055df
maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30330
diff
changeset
|
208 |
30314
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
209 original_f = f; # Store for error messages. |
5687 | 210 |
30648
c7a515aa767e
datevec.m: Tweaks to cset e9bfb92dab01 for performance and documentation (bug #47627)
Rik <rik@octave.org>
parents:
30647
diff
changeset
|
211 if (any (strchr (f, "hsfYD", 1))) |
c7a515aa767e
datevec.m: Tweaks to cset e9bfb92dab01 for performance and documentation (bug #47627)
Rik <rik@octave.org>
parents:
30647
diff
changeset
|
212 warning ("Octave:datevec:date-format-spec", ... |
30647
e9bfb92dab01
datevec.m: Emit warning if format specifiers are used with opposite case (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30645
diff
changeset
|
213 ["datevec: Format specifiers for dates should be lower case,", ... |
e9bfb92dab01
datevec.m: Emit warning if format specifiers are used with opposite case (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30645
diff
changeset
|
214 " format specifiers for time should be upper case. ", ... |
e9bfb92dab01
datevec.m: Emit warning if format specifiers are used with opposite case (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30645
diff
changeset
|
215 " Possible issue with 'm' (month) and 'M' (minutes)?"]); |
e9bfb92dab01
datevec.m: Emit warning if format specifiers are used with opposite case (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30645
diff
changeset
|
216 endif |
e9bfb92dab01
datevec.m: Emit warning if format specifiers are used with opposite case (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30645
diff
changeset
|
217 |
8506 | 218 ## Play safe with percent signs. |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
219 f = strrep (f, "%", "%%"); |
5687 | 220 |
221 if (! isempty (strfind (f, "PM")) || ! isempty (strfind (f, "AM"))) | |
222 ampm = true; | |
223 else | |
224 ampm = false; | |
225 endif | |
226 | |
8506 | 227 ## Date part. |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
228 f = regexprep (f, '[Yy][Yy][Yy][Yy]', "%Y"); |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
229 f = regexprep (f, '[Yy][Yy]', "%y"); |
5687 | 230 f = strrep (f, "mmmm", "%B"); |
231 f = strrep (f, "mmm", "%b"); | |
232 f = strrep (f, "mm", "%m"); | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
233 f = regexprep (f, '[Dd][Dd][Dd][Dd]', "%A"); |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
234 f = regexprep (f, '[Dd][Dd][Dd]', "%a"); |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
235 f = regexprep (f, '[Dd][Dd]', "%d"); |
5687 | 236 |
8506 | 237 ## Time part. |
5687 | 238 if (ampm) |
239 f = strrep (f, "HH", "%I"); | |
240 f = strrep (f, "PM", "%p"); | |
241 f = strrep (f, "AM", "%p"); | |
242 else | |
243 f = strrep (f, "HH", "%H"); | |
244 endif | |
245 f = strrep (f, "MM", "%M"); | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
246 f = regexprep (f, '[Ss][Ss]', "%S"); |
5687 | 247 |
30314
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
248 ## Check for conflicting or repeated fields. |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
249 ## Only warn, not error, if we may be confused by an original '%'s. |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
250 if (index (original_f, "%")) |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
251 err_or_warn = @warning; |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
252 else |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
253 err_or_warn = @error; |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
254 endif |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
255 |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
256 if (numel (strfind (f, "%Y")) + numel (strfind (f, "%y")) > 1) |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
257 err_or_warn ("datevec: multiple year specifiers in %s", original_f); |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
258 elseif (numel (strfind (f, "%m")) + numel (strfind (f, "%b")) |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
259 + numel (strfind (f, "%B")) > 1) |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
260 err_or_warn ("datevec: multiple month specifiers in %s", original_f); |
30645
beac32c0e9c7
datevec.m: Allow day and day of week to occur in the same format string (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
261 elseif (numel (strfind (f, "%d")) > 1) |
30314
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
262 err_or_warn ("datevec: multiple day specifiers in %s", original_f); |
30645
beac32c0e9c7
datevec.m: Allow day and day of week to occur in the same format string (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
263 elseif (numel (strfind (f, "%a"))+ numel (strfind (f, "%A")) > 1) |
beac32c0e9c7
datevec.m: Allow day and day of week to occur in the same format string (bug #47627).
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
264 err_or_warn ("datevec: multiple day of week specifiers in %s", original_f); |
30314
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
265 elseif (numel (strfind (f, "%H")) + numel (strfind (f, "%I")) > 1) |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
266 err_or_warn ("datevec: multiple hour specifiers in %s", original_f); |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
267 elseif (numel (strfind (f, "%M")) > 1) |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
268 err_or_warn ("datevec: multiple minute specifiers in %s", original_f); |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
269 elseif (numel (strfind (f, "%S")) > 1) |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
270 err_or_warn ("datevec: multiple second specifiers in %s", original_f); |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
271 endif |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
272 |
8411
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
273 rY = rindex (f, "%Y"); |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
274 ry = rindex (f, "%y"); |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
275 |
8506 | 276 ## Check whether we need to give default values. |
277 ## Possible error when string contains "%%". | |
8411
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
278 fy = rY || ry; |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
279 fm = index (f, "%m") || index (f, "%b") || index (f, "%B"); |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
280 fd = index (f, "%d") || index (f, "%a") || index (f, "%A"); |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
281 fh = index (f, "%H") || index (f, "%I"); |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
282 fmi = index (f, "%M"); |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
283 fs = index (f, "%S"); |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
284 |
11086
af03ff97df7b
datevec.m: use endfunction to mark end of primary function and subfunctions
John W. Eaton <jwe@octave.org>
parents:
10793
diff
changeset
|
285 endfunction |
8411
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
286 |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
287 function [found, y, m, d, h, mi, s] = __date_str2vec__ (ds, p, f, rY, ry, fy, fm, fd, fh, fmi, fs) |
69d45a4c7d94
avoid repeated parsing of format string in datevec
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
7044
diff
changeset
|
288 |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
289 ## Local time zone is irrelevant, and potentially dangerous, when using |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
290 ## strptime to simply convert a string into a broken down struct tm. |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
291 ## Set and restore TZ so time is parsed exactly as-is. See bug #36954. |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
292 TZ_orig = getenv ("TZ"); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
293 unwind_protect |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
294 setenv ("TZ", "UTC0"); |
20643
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
295 |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
296 idx = strfind (f, "FFF"); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
297 if (! isempty (idx)) |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
298 ## Kludge to handle FFF millisecond format since strptime does not. |
20715
5b7643257978
Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents:
20677
diff
changeset
|
299 |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
300 ## Find location of FFF in ds. |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
301 ## Might not match idx because of things like yyyy -> %y. |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
302 [~, nc] = strptime (ds, f(1:idx-1)); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
303 |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
304 msec = ds(nc:min (nc+2,end)); # pull 3-digit fractional seconds. |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
305 msec_idx = find (! isdigit (msec), 1); |
20715
5b7643257978
Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents:
20677
diff
changeset
|
306 |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
307 if (! isempty (msec_idx)) # non-digits in msec |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
308 msec = msec(1:msec_idx-1); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
309 msec(end+1:3) = "0"; # pad msec with trailing zeros |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
310 ds = [ds(1:(nc-1)), msec, ds((nc-1)+msec_idx:end)]; # zero pad ds |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
311 elseif (numel (msec) < 3) # less than three digits in msec |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
312 m_len = numel (msec); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
313 msec(end+1:3) = "0"; # pad msec with trailing zeros |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
314 ds = [ds(1:(nc-1)), msec, ds(nc+m_len:end)]; # zero pad ds as well |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
315 endif |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
316 |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
317 ## replace FFF with digits to guarantee match in strptime. |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
318 f(idx:idx+2) = msec; |
20715
5b7643257978
Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents:
20677
diff
changeset
|
319 |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
320 if (nc > 0) |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
321 [tm, nc] = strptime (ds, f); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
322 tm.usec = 1000 * str2double (msec); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
323 endif |
20715
5b7643257978
Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents:
20677
diff
changeset
|
324 |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
325 else |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
326 [tm, nc] = strptime (ds, f); |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
327 endif |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
328 unwind_protect_cleanup |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
329 if (isempty (TZ_orig)) |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
330 unsetenv ("TZ"); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
331 else |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
332 setenv ("TZ", TZ_orig); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
333 endif |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
334 end_unwind_protect |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19384
diff
changeset
|
335 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
336 if (nc == columns (ds) + 1) |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
337 found = true; |
5687 | 338 y = tm.year + 1900; m = tm.mon + 1; d = tm.mday; |
339 h = tm.hour; mi = tm.min; s = tm.sec + tm.usec / 1e6; | |
340 if (rY < ry) | |
341 if (y > 1999) | |
342 y -= 2000; | |
343 else | |
344 y -= 1900; | |
345 endif | |
346 y += p - mod (p, 100); | |
347 if (y < p) | |
348 y += 100; | |
349 endif | |
350 endif | |
351 if (! fy && ! fm && ! fd) | |
8506 | 352 tmp = localtime (time ()); |
14743
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
353 ## default is January 1st of current year |
8506 | 354 y = tmp.year + 1900; |
14743
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
355 m = 1; |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
356 d = 1; |
5687 | 357 elseif (! fy && fm && fd) |
8506 | 358 tmp = localtime (time ()); |
359 y = tmp.year + 1900; | |
5687 | 360 elseif (fy && fm && ! fd) |
361 d = 1; | |
362 endif | |
363 if (! fh && ! fmi && ! fs) | |
364 h = mi = s = 0; | |
365 elseif (fh && fmi && ! fs) | |
366 s = 0; | |
367 endif | |
368 else | |
369 y = m = d = h = mi = s = 0; | |
370 found = false; | |
371 endif | |
372 | |
11086
af03ff97df7b
datevec.m: use endfunction to mark end of primary function and subfunctions
John W. Eaton <jwe@octave.org>
parents:
10793
diff
changeset
|
373 endfunction |
5687 | 374 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
375 |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
376 %!demo |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
377 %! ## Current date and time |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
378 %! datevec (now ()) |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
379 |
14743
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
380 %!shared yr |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
381 %! yr = datevec (now)(1); # Some tests could fail around midnight! |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
382 ## tests for standard formats: 0, 1, 2, 6, 13, 14, 15, 16, 23 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
383 %!assert (datevec ("07-Sep-2000 15:38:09"), [2000,9,7,15,38,9]) |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
384 %!assert (datevec ("07-Sep-2000"), [2000,9,7,0,0,0]) |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
385 %!assert (datevec ("09/07/00"), [2000,9,7,0,0,0]) |
14743
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
386 %!assert (datevec ("09/13"), [yr,9,13,0,0,0]) |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
387 %!assert (datevec ("15:38:09"), [yr,1,1,15,38,9]) |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
388 %!assert (datevec ("3:38:09 PM"), [yr,1,1,15,38,9]) |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
389 %!assert (datevec ("15:38"), [yr,1,1,15,38,0]) |
b7675598094a
datevec.m: Support more date string input formats for Matlab compatibility (bug #36563)
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
390 %!assert (datevec ("03:38 PM"), [yr,1,1,15,38,0]) |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
391 %!assert (datevec ("03/13/1962"), [1962,3,13,0,0,0]) |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
392 |
18747
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
393 ## Test millisecond format FFF |
20643
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
394 %!assert (datevec ("15:38:21.2", "HH:MM:SS.FFF"), [yr,1,1,15,38,21.2]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
395 %!assert (datevec ("15:38:21.25", "HH:MM:SS.FFF"), [yr,1,1,15,38,21.25]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
396 %!assert (datevec ("15:38:21.251", "HH:MM:SS.FFF"), [yr,1,1,15,38,21.251]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
397 |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
398 ## Test millisecond format FFF with AM/PM, and 1,2, or 3 FFF digits |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
399 %!assert (datevec ("06/01/2015 3:07:12.102 PM", "mm/dd/yyyy HH:MM:SS.FFF PM"), |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
400 %! [2015,6,1,15,7,12.102]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
401 %!assert (datevec ("06/01/2015 11:07:12.102 PM", "mm/dd/yyyy HH:MM:SS.FFF PM"), |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
402 %! [2015,6,1,23,7,12.102]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
403 %!assert (datevec ("06/01/2015 3:07:12.102 AM", "mm/dd/yyyy HH:MM:SS.FFF PM"), |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
404 %! [2015,6,1,3,7,12.102]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
405 %!assert (datevec ("06/01/2015 11:07:12.102 AM", "mm/dd/yyyy HH:MM:SS.FFF PM"), |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
406 %! [2015,6,1,11,7,12.102]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
407 %!assert (datevec ("06/01/2015 3:07:12.1 PM", "mm/dd/yyyy HH:MM:SS.FFF PM"), |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
408 %! [2015,6,1,15,7,12.1]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
409 %!assert (datevec ("06/01/2015 3:07:12.12 AM", "mm/dd/yyyy HH:MM:SS.FFF PM"), |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
410 %! [2015,6,1,3,7,12.12]) |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
411 %!assert (datevec ("06/01/2015 3:07:12.12 PM", "mm/dd/yyyy HH:MM:SS.FFF PM"), |
1a02e15a9f4c
datevec.m: Properly handle FFF millisecond code (bug #46171).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
20162
diff
changeset
|
412 %! [2015,6,1,15,7,12.12]) |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
413 |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
414 ## Test structure of return value |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
415 %!test <*42334> |
18747
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
416 %! [~, ~, d] = datevec ([1 2; 3 4]); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
417 %! assert (d, [1 2; 3 4]); |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
418 |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
419 ## Other tests |
21317
a4faec57f4c8
maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
420 %!assert (datenum (datevec ([-1e4:1e4])), [-1e4:1e4]') |
5687 | 421 %!test |
422 %! t = linspace (-2e5, 2e5, 10993); | |
5860 | 423 %! assert (all (abs (datenum (datevec (t)) - t') < 1e-5)); |
30330
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30314
diff
changeset
|
424 %!assert (double (datevec (int64 (datenum ([2014 6 1])))), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30314
diff
changeset
|
425 %! datevec (datenum ([2014 6 1]))) |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30314
diff
changeset
|
426 %!assert (double (datevec (int64 (datenum ([2014 6 18])))), |
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30314
diff
changeset
|
427 %! datevec (datenum ([2014 6 18]))) |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
428 |
23967
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
429 ## Test parsing of date strings that fall within daylight saving transition |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
430 %!testif ; isunix () <*36954> |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
431 %! zones = { "UTC0" ... |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
432 %! "EST+5EDT,M3.2.0/2,M11.1.0/2" ... America/New_York |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
433 %! "CET-1CEST,M3.5.0/2,M10.5.0/2" ... Europe/Berlin |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
434 %! "CLT+4CLST,M8.2.0/0,M5.2.0/0" ... America/Santiago |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
435 %! "LHST-10:30LHDT-11,M10.1.0/2,M4.1.0/2" ... Australia/Lord_Howe |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
436 %! ":America/Caracas" ... |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
437 %! }; |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
438 %! TZ_orig = getenv ("TZ"); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
439 %! unwind_protect |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
440 %! for i = 1:numel (zones) |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
441 %! setenv ("TZ", zones{i}); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
442 %! ## These specific times were chosen to test conversion during the loss |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
443 %! ## of some amount of local time at the start of daylight saving time in |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
444 %! ## each of the zones listed above. We test all in each time zone to be |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
445 %! ## exhaustive, even though each is problematic for only one of the zones. |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
446 %! assert (datevec ("2017-03-12 02:15:00"), [2017 3 12 2 15 0]); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
447 %! assert (datevec ("2017-03-26 02:15:00"), [2017 3 26 2 15 0]); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
448 %! assert (datevec ("2017-08-13 00:15:00"), [2017 8 13 0 15 0]); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
449 %! assert (datevec ("2017-10-01 02:15:00"), [2017 10 1 2 15 0]); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
450 %! ## This tests a one-time loss of 30 minutes in Venezuela's local time |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
451 %! assert (datevec ("2016-05-01 02:40:00"), [2016 5 1 2 40 0]); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
452 %! endfor |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
453 %! unwind_protect_cleanup |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
454 %! if (isempty (TZ_orig)) |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
455 %! unsetenv ("TZ"); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
456 %! else |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
457 %! setenv ("TZ", TZ_orig); |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
458 %! endif |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
459 %! end_unwind_protect |
df726a12c757
datevec: fix parsing of date strings during daylight saving transition (bug #36954)
Mike Miller <mtmiller@octave.org>
parents:
23573
diff
changeset
|
460 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
461 ## Test input validation |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28789
diff
changeset
|
462 %!error <Invalid call> datevec () |
18747
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
463 %!error <none of the standard formats match> datevec ("foobar") |
9eb72fa5f8b5
datevec.m: Return value with same shape as input (bug #42334).
Sergey Plotnikov <seryozha.plotnikov@gmail.com>
parents:
17744
diff
changeset
|
464 %!error <DATE not parsed correctly with given format> datevec ("foobar", "%d") |
30314
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
465 %!error <multiple year specifiers> datevec ("1/2/30", "mm/yy/yy") |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
466 %!error <multiple month specifiers> datevec ("1/2/30", "mm/mm/yy") |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
467 %!error <multiple day specifiers> datevec ("1/2/30", "mm/dd/dd") |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
468 %!error <multiple hour specifiers> datevec ("15:38:21.251", "HH:HH:SS") |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
469 %!error <multiple minute specifiers> datevec ("15:38:21.251", "MM:MM:SS") |
3e09b065779d
datevec.m: Check that no field (HH, MM etc) is repeated in format (bug #47627).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
29359
diff
changeset
|
470 %!error <multiple second specifiers> datevec ("15:38:21.251", "HH:SS:SS") |
30648
c7a515aa767e
datevec.m: Tweaks to cset e9bfb92dab01 for performance and documentation (bug #47627)
Rik <rik@octave.org>
parents:
30647
diff
changeset
|
471 %!fail ("datevec ('2015-03-31 0:00','YYYY-mm-DD HH:MM')", ... |
c7a515aa767e
datevec.m: Tweaks to cset e9bfb92dab01 for performance and documentation (bug #47627)
Rik <rik@octave.org>
parents:
30647
diff
changeset
|
472 %! "warning", "Format specifiers for dates should be lower case"); |
30649
744778e9210b
datevec.m: Tweak BIST test in c7a515aa767e.
Rik <rik@octave.org>
parents:
30648
diff
changeset
|
473 %!fail ("datevec ('2015-03-31 hh:00','yyyy-mm-dd hh:MM')", ... |
744778e9210b
datevec.m: Tweak BIST test in c7a515aa767e.
Rik <rik@octave.org>
parents:
30648
diff
changeset
|
474 %! "warning", "format specifiers for time should be upper case"); |
30648
c7a515aa767e
datevec.m: Tweaks to cset e9bfb92dab01 for performance and documentation (bug #47627)
Rik <rik@octave.org>
parents:
30647
diff
changeset
|
475 |