This is a static copy of a profile reportHome
datestr (81 calls, 0.120 sec)
Generated 05-Aug-2011 13:01:28 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/timefun/datestr.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
197 | S = dateformverify(dtnumber, d... | 81 | 0.098 s | 81.8% |  |
172 | dtnumber = datenum(D); | 41 | 0.011 s | 9.1% |  |
168 | try | 81 | 0.011 s | 9.1% |  |
195 | end | 1 | 0 s | 0% |  |
194 | end | 1 | 0 s | 0% |  |
All other lines | | | 0 s | 0% |  |
Totals | | | 0.120 s | 100% | |
Children (called functions)
Code Analyzer results
Line number | Message |
128 | Writing ERROR(NARGCHK(...)) is the appropriate way to call this function. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 197 |
Non-code lines (comments, blank lines) | 138 |
Code lines (lines that can run) | 59 |
Code lines that did run | 33 |
Code lines that did not run | 26 |
Coverage (did run/can run) | 55.93 % |
Function listing
time calls line
1 function S = datestr(D,varargin)
2 %DATESTR String representation of date.
3 % S = DATESTR(V) converts one or more date vectors V to date strings S.
4 % Input V must be an M-by-6 matrix containing M full (six-element) date
5 % vectors. Each element of V must be a positive double-precision number.
6 % DATESTR returns a column vector of M date strings, where M is the total
7 % number of date vectors in V.
8 %
9 % S = DATESTR(N) converts one or more serial date numbers N to date
10 % strings S. Input argument N can be a scalar, vector, or
11 % multidimensional array of positive double-precision numbers. DATESTR
12 % returns a column vector of M date strings, where M is the total number
13 % of date numbers in N.
14 %
15 % S = DATESTR(D, F) converts one or more date vectors, serial date
16 % numbers, or date strings D into the same number of date strings S.
17 % Input argument F is a format number or string that determines the
18 % format of the date string output. Valid values for F are given in Table
19 % 1, below. Input F may also contain a free-form date format string
20 % consisting of format tokens as shown in Table 2, below.
21 %
22 % Date strings with 2-character years are interpreted to be within the
23 % 100 years centered around the current year.
24 %
25 % S = DATESTR(S1, F, P) converts date string S1 to date string S,
26 % applying format F to the output string, and using pivot year P as the
27 % starting year of the 100-year range in which a two-character year
28 % resides. The default pivot year is the current year minus 50 years.
29 % F = -1 uses the default format.
30 %
31 % S = DATESTR(...,'local') returns the string in a localized format. The
32 % default (which can be called with 'en_US') is US English. This argument
33 % must come last in the argument sequence.
34 %
35 % Note: The vectorized calling syntax can offer significant performance
36 % improvement for large arrays.
37 %
38 % Table 1: Standard MATLAB Date format definitions
39 %
40 % Number String Example
41 % ===========================================================================
42 % 0 'dd-mmm-yyyy HH:MM:SS' 01-Mar-2000 15:45:17
43 % 1 'dd-mmm-yyyy' 01-Mar-2000
44 % 2 'mm/dd/yy' 03/01/00
45 % 3 'mmm' Mar
46 % 4 'm' M
47 % 5 'mm' 03
48 % 6 'mm/dd' 03/01
49 % 7 'dd' 01
50 % 8 'ddd' Wed
51 % 9 'd' W
52 % 10 'yyyy' 2000
53 % 11 'yy' 00
54 % 12 'mmmyy' Mar00
55 % 13 'HH:MM:SS' 15:45:17
56 % 14 'HH:MM:SS PM' 3:45:17 PM
57 % 15 'HH:MM' 15:45
58 % 16 'HH:MM PM' 3:45 PM
59 % 17 'QQ-YY' Q1-96
60 % 18 'QQ' Q1
61 % 19 'dd/mm' 01/03
62 % 20 'dd/mm/yy' 01/03/00
63 % 21 'mmm.dd,yyyy HH:MM:SS' Mar.01,2000 15:45:17
64 % 22 'mmm.dd,yyyy' Mar.01,2000
65 % 23 'mm/dd/yyyy' 03/01/2000
66 % 24 'dd/mm/yyyy' 01/03/2000
67 % 25 'yy/mm/dd' 00/03/01
68 % 26 'yyyy/mm/dd' 2000/03/01
69 % 27 'QQ-YYYY' Q1-1996
70 % 28 'mmmyyyy' Mar2000
71 % 29 (ISO 8601) 'yyyy-mm-dd' 2000-03-01
72 % 30 (ISO 8601) 'yyyymmddTHHMMSS' 20000301T154517
73 % 31 'yyyy-mm-dd HH:MM:SS' 2000-03-01 15:45:17
74 %
75 % Table 2: Free-form date format symbols
76 %
77 % Symbol Interpretation of format symbol
78 % ===========================================================================
79 % yyyy full year, e.g. 1990, 2000, 2002
80 % yy partial year, e.g. 90, 00, 02
81 % mmmm full name of the month, according to the calendar locale, e.g.
82 % "March", "April" in the UK and USA English locales.
83 % mmm first three letters of the month, according to the calendar
84 % locale, e.g. "Mar", "Apr" in the UK and USA English locales.
85 % mm numeric month of year, padded with leading zeros, e.g. ../03/..
86 % or ../12/..
87 % m capitalized first letter of the month, according to the
88 % calendar locale; for backwards compatibility.
89 % dddd full name of the weekday, according to the calendar locale, e.g.
90 % "Monday", "Tuesday", for the UK and USA calendar locales.
91 % ddd first three letters of the weekday, according to the calendar
92 % locale, e.g. "Mon", "Tue", for the UK and USA calendar locales.
93 % dd numeric day of the month, padded with leading zeros, e.g.
94 % 05/../.. or 20/../..
95 % d capitalized first letter of the weekday; for backwards
96 % compatibility
97 % HH hour of the day, according to the time format. In case the time
98 % format AM | PM is set, HH does not pad with leading zeros. In
99 % case AM | PM is not set, display the hour of the day, padded
100 % with leading zeros. e.g 10:20 PM, which is equivalent to 22:20;
101 % 9:00 AM, which is equivalent to 09:00.
102 % MM minutes of the hour, padded with leading zeros, e.g. 10:15,
103 % 10:05, 10:05 AM.
104 % SS second of the minute, padded with leading zeros, e.g. 10:15:30,
105 % 10:05:30, 10:05:30 AM.
106 % FFF milliseconds field, padded with leading zeros, e.g.
107 % 10:15:30.015.
108 % PM set the time format as time of morning or time of afternoon. AM
109 % or PM is appended to the date string, as appropriate.
110 %
111 % Examples:
112 % DATESTR(now) returns '24-Jan-2003 11:58:15' for that particular date,
113 % on an US English locale DATESTR(now,2) returns 01/24/03, the same as
114 % for DATESTR(now,'mm/dd/yy') DATESTR(now,'dd.mm.yyyy') returns
115 % 24.01.2003 To convert a non-standard date form into a standard MATLAB
116 % dateform, first convert the non-standard date form to a date number,
117 % using DATENUM, for example,
118 % DATESTR(DATENUM('24.01.2003','dd.mm.yyyy'),2) returns 01/24/03.
119 %
120 % See also DATE, DATENUM, DATEVEC, DATETICK.
121
122 % Copyright 1984-2008 The MathWorks, Inc.
123 % $Revision: 1.32.4.19 $ $Date: 2010/08/23 23:13:37 $
124
125 %==============================================================================
126 % handle input arguments
81 127 if (nargin<1) || (nargin>4)
128 error('MATLAB:datestr:Nargin',nargchk(1,4,nargin));
129 end
81 130 last = nargin - 1;
81 131 islocal = 0;
81 132 if last > 0 && ischar(varargin{end})
133 if strcmpi(varargin{end}, 'local')
134 islocal = 1;
135 last = last - 1;
136 elseif strcmpi(varargin{end},'en_us')
137 islocal = 0;
138 last = last - 1;
139 end
140 end
141
81 142 if last > 2
143 error(message('MATLAB:datestr:Nargin'));
81 144 elseif last >= 1
80 145 dateform = varargin{1};
80 146 if last == 2
147 pivotyear = varargin{2};
148 end
80 149 end
150
81 151 isdatestr = ~isnumeric(D);
81 152 if last > 0
80 153 if ~ischar(dateform);
154 % lookup date form string on index
80 155 dateformstr = getdateform(dateform);
156 else
157 dateformstr = dateform;
158 end
1 159 else
1 160 dateformstr = '';
1 161 end
162
81 163 if last == 2 && ischar(pivotyear)
164 error(message('MATLAB:datestr:InputClass'));
165 end
166
167 % Convert strings and clock vectors to date numbers.
0.01 81 168 try
81 169 if isdatestr || (size(D,2)==6 && all(all(D(:,1:5)==fix(D(:,1:5)))) &&...
170 all(abs(sum(D,2)-2000)<500))
41 171 if last <= 1 || ~isdatestr %not a datestring or no pivot year.
0.01 41 172 dtnumber = datenum(D);
173 else %datestring and pivot year were passed in.
174 dtnumber = datenum(D,pivotyear);
175 end
40 176 else %datenum was passed in
40 177 dtnumber = D;
40 178 end
179 catch exception
180 error(message('MATLAB:datestr:ConvertToDateNumber', exception.message));
181 end
182
183 % Determine format if none specified. If all the times are zero,
184 % display using date only. If all dates are all zero display time only.
185 % Otherwise display both time and date.
81 186 dtnumber = dtnumber(:);
81 187 if (last < 1) || (isnumeric(dateform) && (dateform == -1))
1 188 if all(floor(dtnumber)==dtnumber)
189 dateformstr = getdateform(1);
1 190 elseif all(floor(dtnumber)==0)
191 dateformstr = getdateform(16);
1 192 else
1 193 dateformstr = getdateform(0);
1 194 end
1 195 end
196
0.10 81 197 S = dateformverify(dtnumber, dateformstr, islocal);
Other subfunctions in this file are not included in this listing.