1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of datenum_uvmat</title> |
---|
6 | <meta name="keywords" content="datenum_uvmat"> |
---|
7 | <meta name="description" content="'datenum_uvmat': like the Matlab function datenum.m but gives empty output instead of stopping for input error"> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../index.html">Home</a> > <a href="index.html">.</a> > datenum_uvmat.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for . <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>datenum_uvmat |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
24 | <div class="box"><strong>'datenum_uvmat': like the Matlab function datenum.m but gives empty output instead of stopping for input error</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function n = datenum_uvmat(arg1,arg2,arg3,h,min,s) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">'datenum_uvmat': like the Matlab function datenum.m but gives empty output instead of stopping for input error |
---|
31 | -------------------------------------------------------------------------- |
---|
32 | DATENUM Serial date number. |
---|
33 | N = DATENUM(V) converts one or more date vectors V into serial date |
---|
34 | numbers N. Input V can be an M-by-6 or M-by-3 matrix containing M full |
---|
35 | or partial date vectors respectively. DATENUM returns a column vector |
---|
36 | of M date numbers. |
---|
37 | |
---|
38 | A date vector contains six elements, specifying year, month, day, hour, |
---|
39 | minute, and second. A partial date vector has three elements, specifying |
---|
40 | year, month, and day. Each element of V must be a positive double |
---|
41 | precision number. A serial date number of 1 corresponds to Jan-1-0000. |
---|
42 | The year 0000 is merely a reference point and is not intended to be |
---|
43 | interpreted as a real year. |
---|
44 | |
---|
45 | N = DATENUM(S,F) converts one or more date strings S to serial date |
---|
46 | numbers N using format string F. S can be a character array where each |
---|
47 | row corresponds to one date string, or one dimensional cell array of |
---|
48 | strings. DATENUM returns a column vector of M date numbers, where M is |
---|
49 | the number of strings in S. |
---|
50 | |
---|
51 | All of the date strings in S must have the same format F, which must be |
---|
52 | composed of date format symbols according to Table 2 in DATESTR help. |
---|
53 | Formats with 'Q' are not accepted by DATENUM. |
---|
54 | |
---|
55 | Certain formats may not contain enough information to compute a date |
---|
56 | number. In those cases, hours, minutes, and seconds default to 0, days |
---|
57 | default to 1, months default to January, and years default to the |
---|
58 | current year. Date strings with two character years are interpreted to |
---|
59 | be within the 100 years centered around the current year. |
---|
60 | |
---|
61 | N = DATENUM(S,F,P) or N = DATENUM(S,P,F) uses the specified format F |
---|
62 | and the pivot year P to determine the date number N, given the date |
---|
63 | string S. The pivot year is the starting year of the 100-year range in |
---|
64 | which a two-character year resides. The default pivot year is the |
---|
65 | current year minus 50 years. |
---|
66 | |
---|
67 | N = DATENUM(Y,MO,D) and N = DATENUM([Y,MO,D]) return the serial date |
---|
68 | numbers for corresponding elements of the Y,MO,D (year,month,day) |
---|
69 | arrays. Y, MO, and D must be arrays of the same size (or any can be a |
---|
70 | scalar). |
---|
71 | |
---|
72 | N = DATENUM(Y,MO,D,H,MI,S) and N = DATENUM([Y,MO,D,H,MI,S]) return the |
---|
73 | serial date numbers for corresponding elements of the Y,MO,D,H,MI,S |
---|
74 | (year,month,day,hour,minute,second) arrays. The six arguments must be |
---|
75 | arrays of the same size (or any can be a scalar). |
---|
76 | |
---|
77 | N = DATENUM(S) converts the string or date vector (as defined by |
---|
78 | DATEVEC) S into a serial date number. If S is a string, it must be in |
---|
79 | one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR. |
---|
80 | This calling syntax is provided for backward compatibility, and is |
---|
81 | significantly slower than the syntax which specifies the format string. |
---|
82 | If the format is known, the N = DATENUM(S,F) syntax should be used. |
---|
83 | |
---|
84 | N = DATENUM(S,P) converts the date string S, using pivot year P. If the |
---|
85 | format is known, the N = DATENUM(S,F,P) or N = DATENUM(S,P,F) syntax |
---|
86 | should be used. |
---|
87 | |
---|
88 | Note: The vectorized calling syntax can offer significant performance |
---|
89 | improvement for large arrays. |
---|
90 | |
---|
91 | Examples: |
---|
92 | n = datenum('19-May-2000') returns n = 730625. |
---|
93 | n = datenum(2001,12,19) returns n = 731204. |
---|
94 | n = datenum(2001,12,19,18,0,0) returns n = 731204.75. |
---|
95 | n = datenum('19.05.2000','dd.mm.yyyy') returns n = 730625. |
---|
96 | |
---|
97 | See also NOW, DATESTR, DATEVEC, DATETICK.</pre></div> |
---|
98 | |
---|
99 | <!-- crossreference --> |
---|
100 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
101 | This function calls: |
---|
102 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
103 | </ul> |
---|
104 | This function is called by: |
---|
105 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
106 | </ul> |
---|
107 | <!-- crossreference --> |
---|
108 | |
---|
109 | <h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
110 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
111 | <li><a href="#_sub1" class="code">function [y,mo,d,h,mi,s] = datevec(t,varargin)</a></li><li><a href="#_sub2" class="code">function [format] = getformat(str)</a></li></ul> |
---|
112 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
113 | <div class="fragment"><pre>0001 <span class="comment">%'datenum_uvmat': like the Matlab function datenum.m but gives empty output instead of stopping for input error</span> |
---|
114 | 0002 <span class="comment">%--------------------------------------------------------------------------</span> |
---|
115 | 0003 <a name="_sub0" href="#_subfunctions" class="code">function n = datenum_uvmat(arg1,arg2,arg3,h,min,s)</a> |
---|
116 | 0004 <span class="comment">%DATENUM Serial date number.</span> |
---|
117 | 0005 <span class="comment">% N = DATENUM(V) converts one or more date vectors V into serial date</span> |
---|
118 | 0006 <span class="comment">% numbers N. Input V can be an M-by-6 or M-by-3 matrix containing M full</span> |
---|
119 | 0007 <span class="comment">% or partial date vectors respectively. DATENUM returns a column vector</span> |
---|
120 | 0008 <span class="comment">% of M date numbers.</span> |
---|
121 | 0009 <span class="comment">%</span> |
---|
122 | 0010 <span class="comment">% A date vector contains six elements, specifying year, month, day, hour,</span> |
---|
123 | 0011 <span class="comment">% minute, and second. A partial date vector has three elements, specifying</span> |
---|
124 | 0012 <span class="comment">% year, month, and day. Each element of V must be a positive double</span> |
---|
125 | 0013 <span class="comment">% precision number. A serial date number of 1 corresponds to Jan-1-0000.</span> |
---|
126 | 0014 <span class="comment">% The year 0000 is merely a reference point and is not intended to be</span> |
---|
127 | 0015 <span class="comment">% interpreted as a real year.</span> |
---|
128 | 0016 <span class="comment">%</span> |
---|
129 | 0017 <span class="comment">% N = DATENUM(S,F) converts one or more date strings S to serial date</span> |
---|
130 | 0018 <span class="comment">% numbers N using format string F. S can be a character array where each</span> |
---|
131 | 0019 <span class="comment">% row corresponds to one date string, or one dimensional cell array of</span> |
---|
132 | 0020 <span class="comment">% strings. DATENUM returns a column vector of M date numbers, where M is</span> |
---|
133 | 0021 <span class="comment">% the number of strings in S.</span> |
---|
134 | 0022 <span class="comment">%</span> |
---|
135 | 0023 <span class="comment">% All of the date strings in S must have the same format F, which must be</span> |
---|
136 | 0024 <span class="comment">% composed of date format symbols according to Table 2 in DATESTR help.</span> |
---|
137 | 0025 <span class="comment">% Formats with 'Q' are not accepted by DATENUM.</span> |
---|
138 | 0026 <span class="comment">%</span> |
---|
139 | 0027 <span class="comment">% Certain formats may not contain enough information to compute a date</span> |
---|
140 | 0028 <span class="comment">% number. In those cases, hours, minutes, and seconds default to 0, days</span> |
---|
141 | 0029 <span class="comment">% default to 1, months default to January, and years default to the</span> |
---|
142 | 0030 <span class="comment">% current year. Date strings with two character years are interpreted to</span> |
---|
143 | 0031 <span class="comment">% be within the 100 years centered around the current year.</span> |
---|
144 | 0032 <span class="comment">%</span> |
---|
145 | 0033 <span class="comment">% N = DATENUM(S,F,P) or N = DATENUM(S,P,F) uses the specified format F</span> |
---|
146 | 0034 <span class="comment">% and the pivot year P to determine the date number N, given the date</span> |
---|
147 | 0035 <span class="comment">% string S. The pivot year is the starting year of the 100-year range in</span> |
---|
148 | 0036 <span class="comment">% which a two-character year resides. The default pivot year is the</span> |
---|
149 | 0037 <span class="comment">% current year minus 50 years.</span> |
---|
150 | 0038 <span class="comment">%</span> |
---|
151 | 0039 <span class="comment">% N = DATENUM(Y,MO,D) and N = DATENUM([Y,MO,D]) return the serial date</span> |
---|
152 | 0040 <span class="comment">% numbers for corresponding elements of the Y,MO,D (year,month,day)</span> |
---|
153 | 0041 <span class="comment">% arrays. Y, MO, and D must be arrays of the same size (or any can be a</span> |
---|
154 | 0042 <span class="comment">% scalar).</span> |
---|
155 | 0043 <span class="comment">%</span> |
---|
156 | 0044 <span class="comment">% N = DATENUM(Y,MO,D,H,MI,S) and N = DATENUM([Y,MO,D,H,MI,S]) return the</span> |
---|
157 | 0045 <span class="comment">% serial date numbers for corresponding elements of the Y,MO,D,H,MI,S</span> |
---|
158 | 0046 <span class="comment">% (year,month,day,hour,minute,second) arrays. The six arguments must be</span> |
---|
159 | 0047 <span class="comment">% arrays of the same size (or any can be a scalar).</span> |
---|
160 | 0048 <span class="comment">%</span> |
---|
161 | 0049 <span class="comment">% N = DATENUM(S) converts the string or date vector (as defined by</span> |
---|
162 | 0050 <span class="comment">% DATEVEC) S into a serial date number. If S is a string, it must be in</span> |
---|
163 | 0051 <span class="comment">% one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.</span> |
---|
164 | 0052 <span class="comment">% This calling syntax is provided for backward compatibility, and is</span> |
---|
165 | 0053 <span class="comment">% significantly slower than the syntax which specifies the format string.</span> |
---|
166 | 0054 <span class="comment">% If the format is known, the N = DATENUM(S,F) syntax should be used.</span> |
---|
167 | 0055 <span class="comment">%</span> |
---|
168 | 0056 <span class="comment">% N = DATENUM(S,P) converts the date string S, using pivot year P. If the</span> |
---|
169 | 0057 <span class="comment">% format is known, the N = DATENUM(S,F,P) or N = DATENUM(S,P,F) syntax</span> |
---|
170 | 0058 <span class="comment">% should be used.</span> |
---|
171 | 0059 <span class="comment">%</span> |
---|
172 | 0060 <span class="comment">% Note: The vectorized calling syntax can offer significant performance</span> |
---|
173 | 0061 <span class="comment">% improvement for large arrays.</span> |
---|
174 | 0062 <span class="comment">%</span> |
---|
175 | 0063 <span class="comment">% Examples:</span> |
---|
176 | 0064 <span class="comment">% n = datenum('19-May-2000') returns n = 730625.</span> |
---|
177 | 0065 <span class="comment">% n = datenum(2001,12,19) returns n = 731204.</span> |
---|
178 | 0066 <span class="comment">% n = datenum(2001,12,19,18,0,0) returns n = 731204.75.</span> |
---|
179 | 0067 <span class="comment">% n = datenum('19.05.2000','dd.mm.yyyy') returns n = 730625.</span> |
---|
180 | 0068 <span class="comment">%</span> |
---|
181 | 0069 <span class="comment">% See also NOW, DATESTR, DATEVEC, DATETICK.</span> |
---|
182 | 0070 |
---|
183 | 0071 <span class="comment">% Copyright 1984-2004 The MathWorks, Inc.</span> |
---|
184 | 0072 <span class="comment">% $Revision: 1.24.4.7 $ $Date: 2004/10/27 23:53:57 $</span> |
---|
185 | 0073 |
---|
186 | 0074 <span class="keyword">if</span> (nargin<1) || (nargin>6) |
---|
187 | 0075 error(<span class="string">'MATLAB:datenumr:Nargin'</span>,nargchk(1,6,nargin)); |
---|
188 | 0076 <span class="keyword">end</span> |
---|
189 | 0077 |
---|
190 | 0078 <span class="comment">% parse input arguments</span> |
---|
191 | 0079 isdatestr = ~isnumeric(arg1); |
---|
192 | 0080 isdateformat = false; |
---|
193 | 0081 <span class="keyword">if</span> nargin == 2 |
---|
194 | 0082 isdateformat = ischar(arg2); |
---|
195 | 0083 <span class="keyword">elseif</span> nargin == 3 |
---|
196 | 0084 isdateformat = [ischar(arg2),ischar(arg3)]; |
---|
197 | 0085 <span class="keyword">end</span> |
---|
198 | 0086 <span class="comment">% try to convert date string or date vector to a date number</span> |
---|
199 | 0087 <span class="keyword">try</span> |
---|
200 | 0088 <span class="keyword">switch</span> nargin |
---|
201 | 0089 <span class="keyword">case</span> 1 |
---|
202 | 0090 <span class="keyword">if</span> isdatestr |
---|
203 | 0091 n = datenummx(<a href="#_sub1" class="code" title="subfunction [y,mo,d,h,mi,s] = datevec(t,varargin)">datevec</a>(arg1)); |
---|
204 | 0092 <span class="keyword">elseif</span> (size(arg1,2)==3) || (size(arg1,2)==6) |
---|
205 | 0093 n = datenummx(arg1); |
---|
206 | 0094 <span class="keyword">else</span> |
---|
207 | 0095 n = arg1; |
---|
208 | 0096 <span class="keyword">end</span> |
---|
209 | 0097 <span class="keyword">case</span> 2 |
---|
210 | 0098 <span class="keyword">if</span> isdateformat |
---|
211 | 0099 <span class="keyword">if</span> ischar(arg1) |
---|
212 | 0100 arg1 = cellstr(arg1); |
---|
213 | 0101 <span class="keyword">end</span> |
---|
214 | 0102 n = dtstr2dtnummx(arg1,cnv2icudf(arg2)); |
---|
215 | 0103 <span class="keyword">else</span> |
---|
216 | 0104 n = datenummx(<a href="#_sub1" class="code" title="subfunction [y,mo,d,h,mi,s] = datevec(t,varargin)">datevec</a>(arg1,arg2)); |
---|
217 | 0105 <span class="keyword">end</span> |
---|
218 | 0106 <span class="keyword">case</span> 3 |
---|
219 | 0107 <span class="keyword">if</span> any(isdateformat) |
---|
220 | 0108 <span class="keyword">if</span> isdateformat(1) |
---|
221 | 0109 format = arg2; |
---|
222 | 0110 pivot = arg3; |
---|
223 | 0111 <span class="keyword">elseif</span> isdateformat(2) |
---|
224 | 0112 format = arg3; |
---|
225 | 0113 pivot = arg2; |
---|
226 | 0114 <span class="keyword">end</span> |
---|
227 | 0115 <span class="keyword">if</span> ischar(arg1) |
---|
228 | 0116 arg1 = cellstr(arg1); |
---|
229 | 0117 <span class="keyword">end</span> |
---|
230 | 0118 icu_dtformat = cnv2icudf(format); |
---|
231 | 0119 showyr = strfind(icu_dtformat,<span class="string">'y'</span>); |
---|
232 | 0120 <span class="keyword">if</span> ~isempty(showyr) |
---|
233 | 0121 wrtYr = numel(showyr); |
---|
234 | 0122 checkYr = diff(showyr); |
---|
235 | 0123 <span class="keyword">if</span> any(checkYr~=1) |
---|
236 | 0124 error(<span class="string">'MATLAB:datenum:YearFormat'</span>,<span class="string">'Unrecognized year format'</span>); |
---|
237 | 0125 <span class="keyword">end</span> |
---|
238 | 0126 <span class="keyword">switch</span> wrtYr |
---|
239 | 0127 <span class="keyword">case</span> 4, |
---|
240 | 0128 icu_dtformat = strrep(icu_dtformat,<span class="string">'yyyy'</span>,<span class="string">'yy'</span>); |
---|
241 | 0129 <span class="keyword">case</span> 3, |
---|
242 | 0130 icu_dtformat = strrep(icu_dtformat,<span class="string">'yyy'</span>,<span class="string">'yy'</span>); |
---|
243 | 0131 <span class="keyword">end</span> |
---|
244 | 0132 <span class="keyword">end</span> |
---|
245 | 0133 n = dtstr2dtnummx(arg1,icu_dtformat,pivot); |
---|
246 | 0134 <span class="keyword">else</span> |
---|
247 | 0135 n = datenummx(arg1,arg2,arg3); |
---|
248 | 0136 <span class="keyword">end</span> |
---|
249 | 0137 <span class="keyword">case</span> 6, n = datenummx(arg1,arg2,arg3,h,min,s); |
---|
250 | 0138 <span class="keyword">otherwise</span>, error(<span class="string">'MATLAB:datenum:Nargin'</span>,<span class="keyword">...</span> |
---|
251 | 0139 <span class="string">'Incorrect number of arguments'</span>); |
---|
252 | 0140 <span class="keyword">end</span> |
---|
253 | 0141 <span class="keyword">catch</span> |
---|
254 | 0142 err = lasterror; |
---|
255 | 0143 err.message = sprintf(<span class="string">'DATENUM failed.\n%s'</span>,err.message); |
---|
256 | 0144 |
---|
257 | 0145 <span class="keyword">if</span> (nargin == 1 && ~isdatestr) |
---|
258 | 0146 err.identifier = <span class="string">'MATLAB:datenum:ConvertDateNumber'</span>; |
---|
259 | 0147 <span class="keyword">elseif</span> (nargin == 1 && isdatestr) || (isdatestr && any(isdateformat)) |
---|
260 | 0148 err.identifier = <span class="string">'MATLAB:datenum:ConvertDateString'</span>; |
---|
261 | 0149 <span class="keyword">elseif</span> (nargin > 1) && ~isdatestr && ~any(isdateformat) |
---|
262 | 0150 err.identifier = <span class="string">'MATLAB:datenum:ConvertDateVector'</span>; |
---|
263 | 0151 <span class="keyword">end</span> |
---|
264 | 0152 |
---|
265 | 0153 rethrow(err); |
---|
266 | 0154 <span class="keyword">end</span> |
---|
267 | 0155 <span class="keyword">end</span> |
---|
268 | 0156 |
---|
269 | 0157 <a name="_sub1" href="#_subfunctions" class="code">function [y,mo,d,h,mi,s] = datevec(t,varargin)</a> |
---|
270 | 0158 <span class="comment">%DATEVEC Date components.</span> |
---|
271 | 0159 <span class="comment">% V = DATEVEC(N) converts one or more date numbers N to date vectors V. N</span> |
---|
272 | 0160 <span class="comment">% can be a scalar, vector, or multidimensional array of positive date</span> |
---|
273 | 0161 <span class="comment">% numbers. DATEVEC returns an M-by-6 matrix containing M date vectors,</span> |
---|
274 | 0162 <span class="comment">% where M is the total number of date numbers in N.</span> |
---|
275 | 0163 <span class="comment">%</span> |
---|
276 | 0164 <span class="comment">% V = DATEVEC(S,F) converts one or more date strings S to date vectors</span> |
---|
277 | 0165 <span class="comment">% V using format string F to interpret the date strings in S. S can be a</span> |
---|
278 | 0166 <span class="comment">% cell array of strings or a character array where each row corresponds</span> |
---|
279 | 0167 <span class="comment">% to one date string. All of the date strings in S must have the same</span> |
---|
280 | 0168 <span class="comment">% format which must be composed of date format symbols according to</span> |
---|
281 | 0169 <span class="comment">% Table 2 in DATESTR help. Formats with 'Q' are not accepted by DATEVEC.</span> |
---|
282 | 0170 <span class="comment">% DATEVEC returns an M-by-6 matrix of date vectors, where M is the number</span> |
---|
283 | 0171 <span class="comment">% of date strings in S.</span> |
---|
284 | 0172 <span class="comment">%</span> |
---|
285 | 0173 <span class="comment">% Certain formats may not contain enough information to compute a date</span> |
---|
286 | 0174 <span class="comment">% vector. In those cases, hours, minutes, and seconds default to 0, days</span> |
---|
287 | 0175 <span class="comment">% default to 1, months default to January, and years default to the</span> |
---|
288 | 0176 <span class="comment">% current year. Date strings with two character years are interpreted to</span> |
---|
289 | 0177 <span class="comment">% be within the 100 years centered around the current year.</span> |
---|
290 | 0178 <span class="comment">%</span> |
---|
291 | 0179 <span class="comment">% V = DATEVEC(S,F,P) or V = DATEVEC(S,P,F) converts the date string S to</span> |
---|
292 | 0180 <span class="comment">% a date vector V, using the pivot year P and the date format F. The</span> |
---|
293 | 0181 <span class="comment">% pivot year is the starting year of the 100-year range in which a</span> |
---|
294 | 0182 <span class="comment">% two-character year resides. The default pivot year is the current year</span> |
---|
295 | 0183 <span class="comment">% minus 50 years.</span> |
---|
296 | 0184 <span class="comment">%</span> |
---|
297 | 0185 <span class="comment">% [Y,MO,D,H,MI,S] = DATEVEC(...) takes any of the two syntaxes shown</span> |
---|
298 | 0186 <span class="comment">% above and returns the components of the date vector as individual</span> |
---|
299 | 0187 <span class="comment">% variables.</span> |
---|
300 | 0188 <span class="comment">%</span> |
---|
301 | 0189 <span class="comment">% V = DATEVEC(S) converts date string S to date vector V. S must be in</span> |
---|
302 | 0190 <span class="comment">% one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.</span> |
---|
303 | 0191 <span class="comment">% This calling syntax is provided for backward compatibility, and is</span> |
---|
304 | 0192 <span class="comment">% significantly slower than the syntax which specifies the format string.</span> |
---|
305 | 0193 <span class="comment">% If the format is known, the V = DATEVEC(S,F) syntax should be used.</span> |
---|
306 | 0194 <span class="comment">%</span> |
---|
307 | 0195 <span class="comment">% V = DAVEVEC(S,P) converts the date string S using pivot year P.</span> |
---|
308 | 0196 <span class="comment">% If the format is known, the V = DATEVEC(S,F,P) or V = DATEVEC(S,P,F)</span> |
---|
309 | 0197 <span class="comment">% syntax should be used.</span> |
---|
310 | 0198 <span class="comment">%</span> |
---|
311 | 0199 <span class="comment">% Note 1: If more than one input argument is used, the first argument</span> |
---|
312 | 0200 <span class="comment">% must be a date string or array of date strings.</span> |
---|
313 | 0201 <span class="comment">%</span> |
---|
314 | 0202 <span class="comment">% Note 2: The vectorized calling syntax can offer significant performance</span> |
---|
315 | 0203 <span class="comment">% improvement for large arrays.</span> |
---|
316 | 0204 <span class="comment">%</span> |
---|
317 | 0205 <span class="comment">% Examples</span> |
---|
318 | 0206 <span class="comment">% d = '12/24/1984';</span> |
---|
319 | 0207 <span class="comment">% t = 725000.00;</span> |
---|
320 | 0208 <span class="comment">% c = datevec(d) or c = datevec(t) produce c = [1984 12 24 0 0 0].</span> |
---|
321 | 0209 <span class="comment">% [y,m,d,h,mi,s] = datevec(d) returns y=1984, m=12, d=24, h=0, mi=0, s=0.</span> |
---|
322 | 0210 <span class="comment">% c = datevec('5/6/03') produces c = [2003 5 6 0 0 0] until 2054.</span> |
---|
323 | 0211 <span class="comment">% c = datevec('5/6/03',1900) produces c = [1903 5 6 0 0 0].</span> |
---|
324 | 0212 <span class="comment">% c = datevec('19.05.2000','dd.mm.yyyy') produces c = [2000 5 19 0 0 0].</span> |
---|
325 | 0213 <span class="comment">%</span> |
---|
326 | 0214 <span class="comment">% See also DATENUM, DATESTR, CLOCK, DATETICK.</span> |
---|
327 | 0215 |
---|
328 | 0216 <span class="comment">% Copyright 1984-2004 The MathWorks, Inc.</span> |
---|
329 | 0217 <span class="comment">% $Revision: 1.28.4.11 $ $Date: 2004/10/27 23:53:59 $</span> |
---|
330 | 0218 |
---|
331 | 0219 <span class="keyword">if</span> (nargin<1) || (nargin>3) |
---|
332 | 0220 <span class="comment">% error('MATLAB:datevec:Nargin',nargchk(1,3,nargin));</span> |
---|
333 | 0221 <span class="keyword">return</span> |
---|
334 | 0222 <span class="keyword">end</span> |
---|
335 | 0223 |
---|
336 | 0224 <span class="comment">% parse input arguments</span> |
---|
337 | 0225 isdatestr = ~isnumeric(t); |
---|
338 | 0226 isdateformat = false; |
---|
339 | 0227 <span class="keyword">if</span> ~isdatestr && nargin > 1 |
---|
340 | 0228 warning(<span class="string">'MATLAB:datevec:Inputs'</span>, <span class="keyword">...</span> |
---|
341 | 0229 <span class="string">'Unless the first input argument is a date string, all subsequent\narguments will be ignored.'</span>); |
---|
342 | 0230 <span class="keyword">elseif</span> nargin > 1 |
---|
343 | 0231 isdateformat = cellfun(<span class="string">'isclass'</span>,varargin,<span class="string">'char'</span>); |
---|
344 | 0232 <span class="keyword">if</span> (nargin == 3) |
---|
345 | 0233 <span class="keyword">if</span> ~isdateformat(1) |
---|
346 | 0234 pivotyear = varargin{1}; |
---|
347 | 0235 <span class="keyword">elseif</span> ~isdateformat(2) |
---|
348 | 0236 pivotyear = varargin{2}; |
---|
349 | 0237 <span class="keyword">elseif</span> isdateformat(1) && isdateformat(2) |
---|
350 | 0238 <span class="comment">% error('MATLAB:datevec:DateFormat',...</span> |
---|
351 | 0239 <span class="comment">% 'You specified two date format strings.\nThere can only be one.');</span> |
---|
352 | 0240 <span class="keyword">return</span> |
---|
353 | 0241 <span class="keyword">end</span> |
---|
354 | 0242 <span class="keyword">elseif</span> (nargin == 2) && ~isdateformat |
---|
355 | 0243 pivotyear = varargin{1}; |
---|
356 | 0244 <span class="keyword">end</span> |
---|
357 | 0245 <span class="keyword">end</span> |
---|
358 | 0246 |
---|
359 | 0247 <span class="keyword">if</span> isdatestr && isempty(t) |
---|
360 | 0248 <span class="keyword">if</span> nargout <= 1 |
---|
361 | 0249 y = zeros(0,6); |
---|
362 | 0250 <span class="keyword">else</span> |
---|
363 | 0251 [y,mo,d,h,mi,s] = deal(zeros(0,0)); |
---|
364 | 0252 <span class="keyword">end</span>; |
---|
365 | 0253 warning(<span class="string">'MATLAB:datevec:EmptyDate'</span>,<span class="keyword">...</span> |
---|
366 | 0254 <span class="string">'Usage of DATEVEC with empty date strings is not supported.\nResults may change in future versions.'</span>); |
---|
367 | 0255 <span class="keyword">return</span>; |
---|
368 | 0256 <span class="keyword">end</span> |
---|
369 | 0257 |
---|
370 | 0258 <span class="comment">% branch to appropriate date string parser</span> |
---|
371 | 0259 <span class="keyword">if</span> isdatestr |
---|
372 | 0260 <span class="comment">% a date format string was specified</span> |
---|
373 | 0261 <span class="comment">% map date format to ICU date format tokens</span> |
---|
374 | 0262 <span class="keyword">if</span> ischar(t) |
---|
375 | 0263 <span class="comment">% convert to cellstring.</span> |
---|
376 | 0264 t = cellstr(t); |
---|
377 | 0265 <span class="keyword">end</span> |
---|
378 | 0266 icu_dtformat = {}; |
---|
379 | 0267 <span class="keyword">if</span> ~any(isdateformat) |
---|
380 | 0268 format = <a href="#_sub2" class="code" title="subfunction [format] = getformat(str)">getformat</a>(t); |
---|
381 | 0269 <span class="keyword">if</span> ~isempty(format) |
---|
382 | 0270 icu_dtformat = cnv2icudf(format); |
---|
383 | 0271 <span class="keyword">end</span> |
---|
384 | 0272 <span class="keyword">else</span> |
---|
385 | 0273 icu_dtformat = cnv2icudf(varargin{isdateformat}); |
---|
386 | 0274 <span class="keyword">end</span> |
---|
387 | 0275 <span class="keyword">if</span> ~isempty(icu_dtformat) |
---|
388 | 0276 <span class="comment">% call ICU MEX function to parse date string to date vector</span> |
---|
389 | 0277 <span class="keyword">try</span> |
---|
390 | 0278 <span class="keyword">if</span> nargin < 2 || (nargin == 2 && any(isdateformat)) |
---|
391 | 0279 y = dtstr2dtvecmx(t,icu_dtformat); |
---|
392 | 0280 <span class="keyword">else</span> |
---|
393 | 0281 showyr = findstr(icu_dtformat,<span class="string">'y'</span>); |
---|
394 | 0282 <span class="keyword">if</span> ~isempty(showyr) |
---|
395 | 0283 wrtYr = numel(showyr); |
---|
396 | 0284 <span class="keyword">if</span> showyr(end) - showyr(1) >= wrtYr |
---|
397 | 0285 <span class="comment">% error('MATLAB:datevec:YearFormat','Unrecognized year format');</span> |
---|
398 | 0286 <span class="keyword">return</span> |
---|
399 | 0287 <span class="keyword">end</span> |
---|
400 | 0288 <span class="keyword">switch</span> wrtYr |
---|
401 | 0289 <span class="keyword">case</span> 4, |
---|
402 | 0290 icu_dtformat = strrep(icu_dtformat,<span class="string">'yyyy'</span>,<span class="string">'yy'</span>); |
---|
403 | 0291 <span class="keyword">case</span> 3, |
---|
404 | 0292 icu_dtformat = strrep(icu_dtformat,<span class="string">'yyy'</span>,<span class="string">'yy'</span>); |
---|
405 | 0293 <span class="keyword">end</span> |
---|
406 | 0294 <span class="keyword">end</span> |
---|
407 | 0295 y = dtstr2dtvecmx(t,icu_dtformat,pivotyear); |
---|
408 | 0296 <span class="keyword">end</span> |
---|
409 | 0297 <span class="keyword">if</span> nargout > 1 |
---|
410 | 0298 mo = y(:,2); |
---|
411 | 0299 d = y(:,3); |
---|
412 | 0300 h = y(:,4); |
---|
413 | 0301 mi = y(:,5); |
---|
414 | 0302 s = y(:,6); |
---|
415 | 0303 y = y(:,1); |
---|
416 | 0304 <span class="keyword">end</span> |
---|
417 | 0305 <span class="keyword">catch</span> |
---|
418 | 0306 err = lasterror; |
---|
419 | 0307 err.identifier = <span class="string">'MATLAB:datevec:dtstr2dtvecmx'</span>; |
---|
420 | 0308 err.message = sprintf([<span class="string">'DATEVEC failed, calling DTSTR2DTVECMX.\n'</span><span class="keyword">...</span><span class="comment"> </span> |
---|
421 | 0309 <span class="string">'%s'</span>],err.message); |
---|
422 | 0310 rethrow(err); |
---|
423 | 0311 <span class="keyword">end</span> |
---|
424 | 0312 <span class="keyword">else</span> |
---|
425 | 0313 <span class="comment">%last resort!!!</span> |
---|
426 | 0314 <span class="keyword">if</span> ischar(t) |
---|
427 | 0315 m = size(t,1); |
---|
428 | 0316 <span class="keyword">else</span> |
---|
429 | 0317 m = length(t); |
---|
430 | 0318 <span class="keyword">end</span> |
---|
431 | 0319 y = zeros(m,6); |
---|
432 | 0320 t = lower(t); |
---|
433 | 0321 <span class="comment">% ampmtokens = lower(getampmtokensmx);</span> |
---|
434 | 0322 amtok = <span class="string">'am'</span>; <span class="comment">%ampmtokens{1};</span> |
---|
435 | 0323 amtok0 = <span class="string">'am'</span>; |
---|
436 | 0324 pmtok = <span class="string">'pm'</span>;<span class="comment">%ampmtokens{2};</span> |
---|
437 | 0325 pmtok0 = <span class="string">'pm'</span>; |
---|
438 | 0326 M={<span class="string">'jan'</span>;<span class="string">'feb'</span>;<span class="string">'mar'</span>;<span class="string">'apr'</span>;<span class="string">'may'</span>;<span class="string">'jun'</span>;<span class="string">'jul'</span>;<span class="string">'aug'</span>;<span class="string">'sept'</span>;<span class="string">'oct'</span>;<span class="string">'nov'</span>;<span class="string">'dec'</span>}; |
---|
439 | 0327 M0=M; |
---|
440 | 0328 <span class="comment">% M = lower(getmonthnames);</span> |
---|
441 | 0329 <span class="comment">% M0 = lower(getmonthnames(0)); % fall-back list of English short month names.</span> |
---|
442 | 0330 <span class="keyword">try</span> |
---|
443 | 0331 <span class="keyword">for</span> i = 1:m |
---|
444 | 0332 <span class="comment">% Convert date input to date vector</span> |
---|
445 | 0333 <span class="comment">% Initially, the six fields are all unknown.</span> |
---|
446 | 0334 c(1,1:6) = NaN; |
---|
447 | 0335 pm = -1; <span class="comment">% means am or pm is not in datestr</span> |
---|
448 | 0336 <span class="keyword">if</span> ischar(t) |
---|
449 | 0337 str = t(i,:); |
---|
450 | 0338 <span class="keyword">else</span> |
---|
451 | 0339 str = t{i}; |
---|
452 | 0340 <span class="keyword">end</span> |
---|
453 | 0341 d = [<span class="string">' '</span> str <span class="string">' '</span>]; |
---|
454 | 0342 |
---|
455 | 0343 <span class="comment">% Replace 'a ' or 'am', 'p ' or 'pm' with ': '.</span> |
---|
456 | 0344 p = max(find(d == amtok(1) | d == pmtok(1) | <span class="keyword">...</span> |
---|
457 | 0345 d == amtok0(1)| d == pmtok0(1))); |
---|
458 | 0346 <span class="keyword">if</span> ~isempty(p) |
---|
459 | 0347 <span class="keyword">if</span> (d(p+1) == amtok(2) | <span class="keyword">...</span> |
---|
460 | 0348 d(p+1) == amtok0(2)| isspace(d(p+1))) & <span class="keyword">...</span> |
---|
461 | 0349 d(p-1) ~= lower(<span class="string">'e'</span>) |
---|
462 | 0350 pm = (d(p) == pmtok(1) | d(p) == pmtok0(1)); |
---|
463 | 0351 <span class="keyword">if</span> d(p-1) == <span class="string">' '</span> |
---|
464 | 0352 d(p-1:p+1) = <span class="string">': '</span>; |
---|
465 | 0353 <span class="keyword">else</span> |
---|
466 | 0354 d(p:p+1) = <span class="string">': '</span>; |
---|
467 | 0355 <span class="keyword">end</span> |
---|
468 | 0356 <span class="keyword">end</span> |
---|
469 | 0357 <span class="keyword">end</span> |
---|
470 | 0358 |
---|
471 | 0359 <span class="comment">% Any remaining letters must be in the month field</span> |
---|
472 | 0360 p = find(isletter(d)); |
---|
473 | 0361 |
---|
474 | 0362 <span class="comment">% Test length of string to catch a bogus date string.</span> |
---|
475 | 0363 <span class="comment">% Get index of month in list of months of year</span> |
---|
476 | 0364 <span class="comment">% replace with spaces, month name in date string.</span> |
---|
477 | 0365 <span class="comment">% If native month name lookup fails, fall back on</span> |
---|
478 | 0366 <span class="comment">% list of English month names.</span> |
---|
479 | 0367 <span class="keyword">if</span> ~isempty(p) && numel(d)>4 |
---|
480 | 0368 k = min(p); |
---|
481 | 0369 <span class="keyword">if</span> d(k+3) == <span class="string">'.'</span>, d(k+3) = <span class="string">' '</span>; <span class="keyword">end</span> |
---|
482 | 0370 monthidx = ~cellfun(<span class="string">'isempty'</span>,strfind(M,d(k:k+2))); |
---|
483 | 0371 <span class="keyword">if</span> ~any(monthidx) |
---|
484 | 0372 monthidx = ~cellfun(<span class="string">'isempty'</span>,strfind(M0,d(k:k+2))); |
---|
485 | 0373 <span class="keyword">if</span> ~any(monthidx) |
---|
486 | 0374 <span class="comment">% error('MATLAB:datevec:MonthOfYear',...</span> |
---|
487 | 0375 <span class="comment">% 'Failed to lookup month of year.');</span> |
---|
488 | 0376 <span class="keyword">return</span> |
---|
489 | 0377 <span class="keyword">end</span> |
---|
490 | 0378 <span class="keyword">end</span> |
---|
491 | 0379 c(2) = find(monthidx); |
---|
492 | 0380 d(p) = char(<span class="string">' '</span>*ones(size(p))); |
---|
493 | 0381 <span class="keyword">end</span> |
---|
494 | 0382 |
---|
495 | 0383 <span class="comment">% Find all nonnumbers.</span> |
---|
496 | 0384 p = find((d < <span class="string">'0'</span> | d > <span class="string">'9'</span>) & (d ~= <span class="string">'.'</span>)); |
---|
497 | 0385 |
---|
498 | 0386 <span class="comment">% Pick off and classify numeric fields, one by one.</span> |
---|
499 | 0387 <span class="comment">% Colons delinate hour, minutes and seconds.</span> |
---|
500 | 0388 |
---|
501 | 0389 k = 1; |
---|
502 | 0390 <span class="keyword">while</span> k < length(p) |
---|
503 | 0391 <span class="keyword">if</span> d(p(k)) ~= <span class="string">' '</span> && d(p(k)+1) == <span class="string">'-'</span> |
---|
504 | 0392 f = str2double(d(p(k)+1:p(k+2)-1)); |
---|
505 | 0393 k = k+1; |
---|
506 | 0394 <span class="keyword">else</span> |
---|
507 | 0395 f = str2double(d(p(k)+1:p(k+1)-1)); |
---|
508 | 0396 <span class="keyword">end</span> |
---|
509 | 0397 <span class="keyword">if</span> ~isnan(f) |
---|
510 | 0398 <span class="keyword">if</span> d(p(k))==<span class="string">':'</span> || d(p(k+1))==<span class="string">':'</span> |
---|
511 | 0399 <span class="keyword">if</span> isnan(c(4)) |
---|
512 | 0400 c(4) = f; <span class="comment">% hour</span> |
---|
513 | 0401 <span class="comment">% Add 12 if pm specified and hour isn't 12</span> |
---|
514 | 0402 <span class="keyword">if</span> pm == 1 && f ~= 12 |
---|
515 | 0403 c(4) = f+12; |
---|
516 | 0404 <span class="keyword">elseif</span> pm == 0 && f == 12 |
---|
517 | 0405 c(4) = 0; |
---|
518 | 0406 <span class="keyword">end</span> |
---|
519 | 0407 <span class="keyword">elseif</span> isnan(c(5)) |
---|
520 | 0408 c(5) = f; <span class="comment">% minutes</span> |
---|
521 | 0409 <span class="keyword">elseif</span> isnan(c(6)) |
---|
522 | 0410 c(6) = f; <span class="comment">% seconds</span> |
---|
523 | 0411 <span class="keyword">else</span> |
---|
524 | 0412 <span class="comment">% error('MATLAB:datevec:NumberOfTimeFields',...</span> |
---|
525 | 0413 <span class="comment">% 'Too many time fields in %s', str);</span> |
---|
526 | 0414 <span class="keyword">return</span> |
---|
527 | 0415 <span class="keyword">end</span> |
---|
528 | 0416 <span class="keyword">elseif</span> isnan(c(2)) |
---|
529 | 0417 <span class="keyword">if</span> f > 12 |
---|
530 | 0418 <span class="comment">% error('MATLAB:datevec:IllegalDateField',...</span> |
---|
531 | 0419 <span class="comment">% '%s is too large to be a month.',num2str(f));</span> |
---|
532 | 0420 <span class="keyword">return</span> |
---|
533 | 0421 <span class="keyword">end</span> |
---|
534 | 0422 c(2) = f; <span class="comment">% month</span> |
---|
535 | 0423 <span class="keyword">elseif</span> isnan(c(3)) |
---|
536 | 0424 c(3) = f; <span class="comment">% date</span> |
---|
537 | 0425 <span class="keyword">elseif</span> isnan(c(1)) |
---|
538 | 0426 <span class="keyword">if</span> (f >= 0) & (p(k+1)-p(k) == 3) <span class="comment">% two char year</span> |
---|
539 | 0427 <span class="keyword">if</span> nargin < 2 |
---|
540 | 0428 clk = clock; |
---|
541 | 0429 pivotyear = clk(1)-50; <span class="comment">%(current year-50 years)</span> |
---|
542 | 0430 <span class="keyword">end</span> |
---|
543 | 0431 <span class="comment">% Moving 100 year window centered around current year</span> |
---|
544 | 0432 c(1) = pivotyear+rem(f+100-rem(pivotyear,100),100); |
---|
545 | 0433 <span class="keyword">else</span> |
---|
546 | 0434 c(1) = f; <span class="comment">% year</span> |
---|
547 | 0435 <span class="keyword">end</span> |
---|
548 | 0436 <span class="keyword">else</span> |
---|
549 | 0437 <span class="comment">% error('MATLAB:datevec:NumberOfDateFields',...</span> |
---|
550 | 0438 <span class="comment">% 'Too many date fields in %s', str);</span> |
---|
551 | 0439 <span class="keyword">return</span> |
---|
552 | 0440 <span class="keyword">end</span> |
---|
553 | 0441 <span class="keyword">end</span> |
---|
554 | 0442 k = k+1; |
---|
555 | 0443 <span class="keyword">end</span> |
---|
556 | 0444 |
---|
557 | 0445 <span class="keyword">if</span> sum(isnan(c)) >= 5 |
---|
558 | 0446 <span class="comment">% error('MATLAB:datevec:ParseDateString',...</span> |
---|
559 | 0447 <span class="comment">% 'Cannot parse date %s', str);</span> |
---|
560 | 0448 <span class="keyword">return</span> |
---|
561 | 0449 <span class="keyword">end</span> |
---|
562 | 0450 <span class="comment">% If any field has not been specified</span> |
---|
563 | 0451 <span class="keyword">if</span> isnan(c(1)), clk = clock; c(1) = clk(1); <span class="keyword">end</span> |
---|
564 | 0452 <span class="keyword">if</span> isnan(c(2)), c(2) = 1; <span class="keyword">end</span>; |
---|
565 | 0453 <span class="keyword">if</span> isnan(c(3)), c(3) = 1; <span class="keyword">end</span>; |
---|
566 | 0454 <span class="keyword">if</span> isnan(c(4)), c(4) = 0; <span class="keyword">end</span>; |
---|
567 | 0455 <span class="keyword">if</span> isnan(c(5)), c(5) = 0; <span class="keyword">end</span>; |
---|
568 | 0456 <span class="keyword">if</span> isnan(c(6)), c(6) = 0; <span class="keyword">end</span>; |
---|
569 | 0457 |
---|
570 | 0458 <span class="comment">% Normalize components to correct ranges.</span> |
---|
571 | 0459 y(i,:) = datevecmx(datenummx(c)); |
---|
572 | 0460 <span class="keyword">end</span> |
---|
573 | 0461 <span class="keyword">catch</span> |
---|
574 | 0462 err = lasterror; |
---|
575 | 0463 err.message = sprintf(<span class="string">'Failed to parse date string.\n%s'</span>,<span class="keyword">...</span> |
---|
576 | 0464 err.message); |
---|
577 | 0465 rethrow(err); |
---|
578 | 0466 <span class="keyword">end</span> |
---|
579 | 0467 <span class="keyword">if</span> nargout > 1 |
---|
580 | 0468 mo = y(:,2); |
---|
581 | 0469 d = y(:,3); |
---|
582 | 0470 h = y(:,4); |
---|
583 | 0471 mi = y(:,5); |
---|
584 | 0472 s = y(:,6); |
---|
585 | 0473 y = y(:,1); |
---|
586 | 0474 <span class="keyword">end</span> |
---|
587 | 0475 <span class="keyword">end</span> |
---|
588 | 0476 <span class="keyword">elseif</span> nargout <= 1 |
---|
589 | 0477 <span class="comment">% date number was specified</span> |
---|
590 | 0478 y = datevecmx(t); |
---|
591 | 0479 <span class="keyword">elseif</span> nargout == 3 |
---|
592 | 0480 <span class="comment">% date number was specified and first three date fields for output</span> |
---|
593 | 0481 [y,mo,d] = datevecmx(t); |
---|
594 | 0482 <span class="keyword">else</span> |
---|
595 | 0483 <span class="comment">% date number was specified and all six date fields for output</span> |
---|
596 | 0484 [y,mo,d,h,mi,s] = datevecmx(t); |
---|
597 | 0485 <span class="keyword">end</span> |
---|
598 | 0486 <span class="keyword">end</span> |
---|
599 | 0487 <span class="comment">%--------------------------------------------------------------------------</span> |
---|
600 | 0488 <span class="comment">%--</span> |
---|
601 | 0489 <a name="_sub2" href="#_subfunctions" class="code">function [format] = getformat(str)</a> |
---|
602 | 0490 format = <span class="string">''</span>; |
---|
603 | 0491 formatstr = cell(11,1); |
---|
604 | 0492 formatstr(1) = {<span class="string">'dd-mmm-yyyy HH:MM:SS'</span>}; |
---|
605 | 0493 formatstr(2) = {<span class="string">'dd-mmm-yyyy'</span>}; |
---|
606 | 0494 formatstr(3) = {<span class="string">'mm/dd/yy'</span>}; |
---|
607 | 0495 formatstr(4) = {<span class="string">'mm/dd'</span>}; |
---|
608 | 0496 formatstr(5) = {<span class="string">'HH:MM:SS'</span>}; |
---|
609 | 0497 formatstr(6) = {<span class="string">'HH:MM:SS PM'</span>}; |
---|
610 | 0498 formatstr(7) = {<span class="string">'HH:MM'</span>}; |
---|
611 | 0499 formatstr(8) = {<span class="string">'HH:MM PM'</span>}; |
---|
612 | 0500 formatstr(9) = {<span class="string">'mm/dd/yyyy'</span>}; |
---|
613 | 0501 formatstr(10) = {<span class="string">'dd-mmm-yyyy HH:MM'</span>}; <span class="comment">%used by finance</span> |
---|
614 | 0502 formatstr(11) = {<span class="string">'dd-mmm-yy'</span>}; <span class="comment">%used by finance</span> |
---|
615 | 0503 |
---|
616 | 0504 AlphaFormats = [1 1 0 0 0 1 0 1 0 1 1]; |
---|
617 | 0505 <span class="comment">%[1 2 6 8 10 11];</span> |
---|
618 | 0506 SlashFormats = [ 0 0 1 1 0 0 0 0 1 0 0]; |
---|
619 | 0507 <span class="comment">%[3 4 9];</span> |
---|
620 | 0508 TwoSlashFormats = [ 0 0 1 0 0 0 0 0 1 0 0]; |
---|
621 | 0509 <span class="comment">%[3 9];</span> |
---|
622 | 0510 DashFormats = [ 1 1 0 0 0 0 0 0 0 1 1]; |
---|
623 | 0511 <span class="comment">%[1 2 10 11];</span> |
---|
624 | 0512 ColonFormats = [1 0 0 0 1 1 1 1 0 1 0]; |
---|
625 | 0513 <span class="comment">%[1 5 6 7 8 10];</span> |
---|
626 | 0514 TwoColonFormats = [1 0 0 0 1 1 0 0 0 0 0]; |
---|
627 | 0515 <span class="comment">%[1 5 6];</span> |
---|
628 | 0516 SpaceFormats = [1 0 0 0 0 1 0 1 0 1 0]; |
---|
629 | 0517 <span class="comment">%[1 6 8 10];</span> |
---|
630 | 0518 |
---|
631 | 0519 bMask = [ 1 1 1 1 1 1 1 1 1 1 1]; |
---|
632 | 0520 |
---|
633 | 0521 <span class="keyword">if</span> length(str) > 1 |
---|
634 | 0522 str = str(1,1); |
---|
635 | 0523 <span class="keyword">end</span> |
---|
636 | 0524 str = strtrim(char(str)); |
---|
637 | 0525 slashes = strfind(str, <span class="string">'/'</span>); |
---|
638 | 0526 <span class="keyword">if</span> ~isempty(slashes) |
---|
639 | 0527 bMask = bMask & SlashFormats; |
---|
640 | 0528 <span class="keyword">if</span> (length(slashes) > 0 && slashes(1) == 2) |
---|
641 | 0529 <span class="keyword">if</span> (length(slashes) > 1 && slashes(2) == 4) |
---|
642 | 0530 str = [<span class="string">'0'</span> str(1:slashes(1)) <span class="string">'0'</span> str(slashes(1)+1:end)]; |
---|
643 | 0531 <span class="keyword">else</span> |
---|
644 | 0532 str = [<span class="string">'0'</span> str]; |
---|
645 | 0533 <span class="keyword">end</span> |
---|
646 | 0534 <span class="keyword">elseif</span> (length(slashes) > 1 && slashes(2) - slashes(1) == 2) |
---|
647 | 0535 str = [str(1:slashes(1)) <span class="string">'0'</span> str(slashes(1)+1:end)]; |
---|
648 | 0536 <span class="keyword">end</span> |
---|
649 | 0537 <span class="keyword">if</span> length(slashes) > 1 |
---|
650 | 0538 bMask = bMask & TwoSlashFormats; |
---|
651 | 0539 <span class="keyword">else</span> |
---|
652 | 0540 bMask = bMask & ~TwoSlashFormats; |
---|
653 | 0541 <span class="keyword">end</span> |
---|
654 | 0542 <span class="keyword">else</span> |
---|
655 | 0543 bMask = bMask & ~SlashFormats; |
---|
656 | 0544 <span class="keyword">end</span> |
---|
657 | 0545 |
---|
658 | 0546 dashes = strfind(str,<span class="string">'-'</span>); |
---|
659 | 0547 <span class="keyword">if</span> ~isempty(dashes) |
---|
660 | 0548 bMask = bMask & DashFormats; |
---|
661 | 0549 <span class="keyword">if</span> (length(dashes) > 0 && dashes(1) == 2) |
---|
662 | 0550 str = [<span class="string">'0'</span> str]; |
---|
663 | 0551 <span class="keyword">end</span> |
---|
664 | 0552 <span class="keyword">else</span> |
---|
665 | 0553 bMask = bMask & ~DashFormats; |
---|
666 | 0554 <span class="keyword">end</span> |
---|
667 | 0555 |
---|
668 | 0556 colons = strfind(str,<span class="string">':'</span>); |
---|
669 | 0557 <span class="keyword">if</span> ~isempty(colons) |
---|
670 | 0558 bMask = bMask & ColonFormats; |
---|
671 | 0559 <span class="keyword">if</span> (length(colons) > 0) && (colons(1) == 2) && (length(str) - colons(end) > 3) |
---|
672 | 0560 str = [<span class="string">'0'</span> str]; |
---|
673 | 0561 <span class="keyword">end</span> |
---|
674 | 0562 <span class="keyword">if</span> length(colons) > 1 |
---|
675 | 0563 bMask = bMask & TwoColonFormats; |
---|
676 | 0564 <span class="keyword">else</span> |
---|
677 | 0565 bMask = bMask & ~TwoColonFormats; |
---|
678 | 0566 <span class="keyword">end</span> |
---|
679 | 0567 <span class="keyword">else</span> |
---|
680 | 0568 bMask = bMask & ~ColonFormats; |
---|
681 | 0569 <span class="keyword">end</span> |
---|
682 | 0570 |
---|
683 | 0571 spaces = strfind(str,<span class="string">' '</span>); |
---|
684 | 0572 <span class="keyword">if</span> ~isempty(spaces) |
---|
685 | 0573 bMask = bMask & SpaceFormats; |
---|
686 | 0574 <span class="keyword">else</span> |
---|
687 | 0575 bMask = bMask & ~SpaceFormats; |
---|
688 | 0576 <span class="keyword">end</span> |
---|
689 | 0577 |
---|
690 | 0578 <span class="keyword">for</span> i = 1:11 |
---|
691 | 0579 <span class="keyword">if</span> bMask(i) |
---|
692 | 0580 <span class="keyword">try</span> |
---|
693 | 0581 str1 = dateformverify(str,char(formatstr(i))); |
---|
694 | 0582 <span class="keyword">if</span> (strcmpi(str, strtrim(str1)) == 1) |
---|
695 | 0583 format = char(formatstr(i)); |
---|
696 | 0584 <span class="keyword">break</span>; |
---|
697 | 0585 <span class="keyword">end</span> |
---|
698 | 0586 <span class="keyword">catch</span> |
---|
699 | 0587 lasterr(<span class="string">''</span>); |
---|
700 | 0588 <span class="keyword">end</span> |
---|
701 | 0589 <span class="keyword">if</span> AlphaFormats(i) |
---|
702 | 0590 <span class="keyword">try</span> |
---|
703 | 0591 str1 = dateformverify(str,char(formatstr(i)),<span class="string">'local'</span>); |
---|
704 | 0592 <span class="keyword">if</span> (strcmpi(str, strtrim(str1)) == 1) |
---|
705 | 0593 format = char(formatstr(i)); |
---|
706 | 0594 <span class="keyword">break</span>; |
---|
707 | 0595 <span class="keyword">end</span> |
---|
708 | 0596 <span class="keyword">catch</span> |
---|
709 | 0597 lasterr(<span class="string">''</span>); |
---|
710 | 0598 <span class="keyword">end</span> |
---|
711 | 0599 <span class="keyword">end</span> |
---|
712 | 0600 <span class="keyword">end</span> |
---|
713 | 0601 <span class="keyword">end</span> |
---|
714 | 0602 <span class="keyword">end</span></pre></div> |
---|
715 | <hr><address>Generated on Fri 13-Nov-2009 11:17:03 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
716 | </body> |
---|
717 | </html> |
---|