This is a static copy of a profile report

Home

datestr (Calls: 20, Time: 0.045 s)
Generated 16-Jul-2020 17:09:37 using performance time.
function in file /Applications/MATLAB_R2020a.app/toolbox/matlab/timefun/datestr.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
...ob>mlprintjob.imwriteArgsForRasterclass method10
imagesci/private/writepngfunction10
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
200
S = dateformverify(dtnumber, d...
200.030 s68.1%
175
dtnumber = datenum(D);
100.003 s6.7%
158
dateformstr = getdateform(date...
200.002 s5.1%
130
D = stringToLegacyText(D);
200.002 s4.9%
134
if last > 0 && (isc...
200.002 s4.0%
All other lines  0.005 s11.4%
Totals  0.045 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
timefun/private/dateformverifyfunction200.029 s66.0%
datenumfunction100.002 s5.1%
datestr>getdateformsubfunction200.001 s2.7%
stringToLegacyTextfunction400.001 s1.4%
Self time (built-ins, overhead, etc.)  0.011 s24.8%
Totals  0.045 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function200
Non-code lines (comments, blank lines)141
Code lines (lines that can run)59
Code lines that did run34
Code lines that did not run25
Coverage (did run/can run)57.63 %
Function listing
time 
Calls 
 line
   1 
function S = datestr(D,varargin)
   2 
%DATESTR Character vector representation of date.
   3 
%   S = DATESTR(V) converts one or more date vectors V to text. S is a
   4 
%   character vector or character array with M rows, where M is the number
   5 
%   of rows in V. Input V must be an M-by-6 matrix containing M full
   6 
%   (six-element) date vectors. Each element of V must be a positive
   7 
%   double-precision number. 
   8 
%
   9 
%   S = DATESTR(N) converts one or more serial date numbers N to text. S
  10 
%   has M rows, where M is the number of rows in N. Input argument N can be
  11 
%   a scalar, vector, or multidimensional array of positive
  12 
%   double-precision numbers.
  13 
%
  14 
%   S = DATESTR(D, F) converts one or more dates into text using the format
  15 
%   F. Input argument F is a format number, character vector, or string
  16 
%   scalar that determines the format of the date character vector output.
  17 
%   D is one or more date vectors, serial date numbers, or a character
  18 
%   array or string array representing dates. Valid values for F are given
  19 
%   in Table 1, below. Input F may also contain a free-form date format
  20 
%   consisting of format tokens as shown in Table 2, below.
  21 
%
  22 
%   Dates in a text format using 2-character years are interpreted to be
  23 
%   within the 100 years centered around the current year.
  24 
%
  25 
%   S = DATESTR(S1, F, P) converts one or more dates into text using format
  26 
%   F. S is a character array using format F and 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. F =
  29 
%   -1 uses the default format.
  30 
%
  31 
%   S = DATESTR(...,'local') returns S in a localized format. The default
  32 
%   (which can be called with 'en_US') is US English. This argument must
  33 
%   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           Format                   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: Date format symbolic identifiers (Examples are in US English)
  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". 
  83 
%   mmm     first three letters of the month, according to the calendar 
  84 
%           locale, e.g. "Mar", "Apr". 
  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". 
  91 
%   ddd     first three letters of the weekday, according to the calendar
  92 
%           locale, e.g. "Mon", "Tue". 
  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 
%   QQ      quarter of year, e.g. Q2
  98 
%   HH      hour of the day, according to the time format. In case the time
  99 
%           format AM | PM is set, HH does not pad with leading zeros. In 
 100 
%           case AM | PM is not set, display the hour of the day, padded 
 101 
%           with leading zeros. e.g 10:20 PM, which is equivalent to 22:20; 
 102 
%           9:00 AM, which is equivalent to 09:00.
 103 
%   MM      minutes of the hour, padded with leading zeros, e.g. 10:15, 
 104 
%           10:05, 10:05 AM.
 105 
%   SS      second of the minute, padded with leading zeros, e.g. 10:15:30,
 106 
%           10:05:30, 10:05:30 AM. 
 107 
%   FFF     milliseconds field, padded with leading zeros, e.g.
 108 
%           10:15:30.015.
 109 
%   PM      AM or PM
 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-2019 The MathWorks, Inc.
 123 

 124 
%==============================================================================
 125 

 126 
import matlab.internal.datatypes.stringToLegacyText
 127 

 128 
% handle input arguments
< 0.001 
     20 
 129
narginchk(1,4); 
  0.002 
     20 
 130
D = stringToLegacyText(D); 
< 0.001 
     20 
 131
last = nargin - 1; 
< 0.001 
     20 
 132
islocal = 0; 
 133 

  0.002 
     20 
 134
if last > 0 && (ischar(varargin{end}) || isstring(varargin{end})) 
 135 
    if strcmpi(varargin{end}, 'local')
 136 
        islocal = 1;
 137 
        last = last - 1;
 138 
    elseif strcmpi(varargin{end},'en_us')
 139 
        islocal = 0;
 140 
        last = last - 1;
 141 
    end
< 0.001 
     20 
 142
end 
 143 

< 0.001 
     20 
 144
if last > 2 
 145 
    % Force narginchk to error
 146 
    narginchk(1,2);
< 0.001 
     20 
 147
elseif last >= 1 
  0.002 
     20 
 148
    dateform = stringToLegacyText(varargin{1}); 
< 0.001 
     20 
 149
    if last == 2 
 150 
        pivotyear =  varargin{2};
< 0.001 
     20 
 151
    end 
< 0.001 
     20 
 152
end 
 153 

< 0.001 
     20 
 154
isdatestr = ~isnumeric(D); 
< 0.001 
     20 
 155
if last > 0 
< 0.001 
     20 
 156
    if ~ischar(dateform) 
 157 
        % lookup date form string on index
  0.002 
     20 
 158
        dateformstr = getdateform(dateform); 
 159 
    else
 160 
        dateformstr = dateform;
< 0.001 
     20 
 161
    end 
 162 
else
 163 
    dateformstr = '';
< 0.001 
     20 
 164
end 
 165 

< 0.001 
     20 
 166
if last == 2 && ischar(pivotyear) 
 167 
    error(message('MATLAB:datestr:InputClass'));
< 0.001 
     20 
 168
end 
 169 

 170 
% Convert character vectors and clock vectors to date numbers.
< 0.001 
     20 
 171
try 
  0.001 
     20 
 172
    if isdatestr || (size(D,2)==6 && all(all(D(:,1:5)==fix(D(:,1:5)))) &&... 
     10 
 173
        all(abs(sum(D,2)-2000)<500))  
< 0.001 
     10 
 174
        if last <= 1 || ~isdatestr  %not a datestring or no pivot year. 
  0.003 
     10 
 175
            dtnumber = datenum(D); 
 176 
        else %datestring and pivot year were passed in.
 177 
            dtnumber = datenum(D,pivotyear);
< 0.001 
     10 
 178
        end 
< 0.001 
     10 
 179
    else %datenum was passed in 
< 0.001 
     10 
 180
        dtnumber = D; 
< 0.001 
     20 
 181
    end 
 182 
catch exception 
 183 
    error(message('MATLAB:datestr:ConvertToDateNumber', exception.message));
< 0.001 
     20 
 184
end 
 185 

 186 
% Determine format if none specified.  If all the times are zero,
 187 
% display using date only.  If all dates are all zero display time only.
 188 
% Otherwise display both time and date.
< 0.001 
     20 
 189
dtnumber = dtnumber(:); 
< 0.001 
     20 
 190
if (last < 1) || (isnumeric(dateform) && (dateform == -1)) 
 191 
   if all(floor(dtnumber)==dtnumber)
 192 
      dateformstr = getdateform(1);
 193 
   elseif all(floor(dtnumber)==0)
 194 
      dateformstr = getdateform(16);
 195 
   else
 196 
      dateformstr = getdateform(0);
 197 
   end
< 0.001 
     20 
 198
end  
 199 

  0.030 
     20 
 200
S = dateformverify(dtnumber, dateformstr, islocal); 

Other subfunctions in this file are not included in this listing.