Skip to content

Commit

Permalink
Fix #37 - datestr
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelson-numerical-software committed Sep 13, 2024
1 parent cdb4602 commit 14f63fb
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 31 deletions.
8 changes: 4 additions & 4 deletions modules/time/builtin/cpp/datevecBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Nelson::TimeGateway::datevecBuiltin(int nLhs, const ArrayOfVector& argIn)
#pragma omp parallel for
#endif
for (ompIndexType k = 0; k < (ompIndexType)len; k++) {
double DT, Y, M, D, H, MN, S;
double DT, Y, M, D, H, MN, S, MS;
DT = ptd[k];
DateVector(DT, Y, M, D, H, MN, S);
DateVector(DT, Y, M, D, H, MN, S, MS);
res[k] = Y;
res[k + len] = M;
res[k + len * 2] = D;
Expand Down Expand Up @@ -86,8 +86,8 @@ Nelson::TimeGateway::datevecBuiltin(int nLhs, const ArrayOfVector& argIn)
#endif
for (ompIndexType k = 0; k < (ompIndexType)len; k++) {
double DT = ptd[k];
double V1, V2, V3, V4, V5, V6;
DateVector(DT, V1, V2, V3, V4, V5, V6);
double V1, V2, V3, V4, V5, V6, V7;
DateVector(DT, V1, V2, V3, V4, V5, V6, V7);
Y[k] = V1;
M[k] = V2;
if (nLhs > 2) {
Expand Down
308 changes: 308 additions & 0 deletions modules/time/help/en_US/xml/datestr.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,308 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xmldoc>
<copyright>SAME AS NELSON SOFTWARE</copyright>

<language>en_US</language>
<keyword>datestr</keyword>
<short_description>Convert date and time to string format.</short_description>

<syntax>
<syntax_item>dateAsString = datestr(dateVector)</syntax_item>
<syntax_item>dateAsString = datestr(dateNumber)</syntax_item>
<syntax_item>dateAsString = datestr(..., formatOut)</syntax_item>
<syntax_item>dateAsString = datestr(dateAsStringIn)</syntax_item>
<syntax_item
>dateAsString = datestr(dateAsStringIn, formatOut, pivotYear)</syntax_item>
<syntax_item>dateAsString = datestr(..., 'local')</syntax_item>
</syntax>



<param_input>

<param_input_item>
<param_name>dateVector</param_name>
<param_description>Date vectors or matrix.</param_description>
</param_input_item>

<param_input_item>
<param_name>dateNumber</param_name>
<param_description
>Serial date numbers: An array of positive double-precision floating-point numbers.</param_description>
</param_input_item>

<param_input_item>
<param_name>formatOut</param_name>
<param_description
>character vector, string scalar or integer value (-1 default): Output format for representing dates and times</param_description>
</param_input_item>

<param_input_item>
<param_name>dateAsStringIn</param_name>
<param_description
>character vector, cell array or string array: text denoting dates and times to convert.</param_description>
</param_input_item>

<param_input_item>
<param_name>pivotYear</param_name>
<param_description
>integer value: present minus 50 years (default).</param_description>
</param_input_item>

<param_input_item>
<param_name>'local'</param_name>
<param_description
>returns the date in the language of the current locale.</param_description>
</param_input_item>

</param_input>


<param_output>
<param_output_item>
<param_name>dateAsString</param_name>
<param_description
>character vector or two-dimensional character array: text denoting dates and time.</param_description>
</param_output_item>
</param_output>

<description>
<p><b
>dateAsString = datestr(dateVector)</b> converts date vectors into text that represents the corresponding dates and times. It returns a character array with <b
>m</b> rows, where <b>m</b> is the number of date vectors in <b
>dateVector</b>.</p>
<p><b
>dateAsString = datestr(dateNumber)</b> converts serial date numbers into text representing dates and times. The output is a character array with <b
>m</b> rows, where <b>m</b> is the number of date numbers in <b
>dateNumber</b>.</p>
<p><b
>dateAsString = datestr(..., formatOut)</b> allows you to specify the format of the output text using <b
>formatOut</b>. You can apply this option with any of the previous input types.</p>
<p><b
>dateAsString = datestr(dateAsStringIn)</b> converts the input string <b
>dateAsStringIn</b> into a text format of day-month-year hour:minute:second. All dates in <b
>dateAsStringIn</b> must follow the same format.</p>
<p><b
>dateAsString = datestr(dateAsStringIn, formatOut, pivotYear)</b> converts <b
>dateAsStringIn</b> into the format specified by <b
>formatOut</b>, while using an optional <b
>pivotYear</b> to interpret two-digit years.</p>
<p><b
>dateAsString = datestr(..., 'local')</b> returns the date in the language of the system's current locale. If <b
>'local'</b> is omitted, the default language is US English. The <b
>'local'</b> option can be used with any of the previous syntaxes, and must be the last argument in the sequence.</p>
<p />
<p>Supported format conversion:</p>
<p><b>dd-mmm-yyyy HH:MM:SS</b> 10-Mar-2010 16:48:17</p>
<p><b>dd-mmm-yyyy</b> 10-Mar-2010</p>
<p><b>mm/dd/yyyy</b> 03/10/2010</p>
<p><b>mm/dd/yy</b> 03/10/00</p>
<p><b>mm/dd</b> 03/10</p>
<p><b>mmm.dd,yyyy HH:MM:SS</b> Mar.10,2010 16:48:17</p>
<p><b>mmm.dd,yyyy</b> Mar.10,2010</p>
<p><b>yyyy-mm-dd HH:MM:SS</b> 2010-03-10 16:48:17</p>
<p><b>yyyy-mm-dd</b> 2010-03-10</p>
<p><b>yyyy/mm/dd</b> 2000/03/10</p>
<p><b>HH:MM:SS</b> 16:48:17</p>
<p><b>HH:MM:SS PM</b> 3:48:17 PM</p>
<p><b>HH:MM</b> 16:48</p>
<p><b>HH:MM PM</b> 3:35 PM</p>
<p />
<p>If format is not specified, the default format is <b>dd-mmm-yyyy</b>.</p>
<p />
<p
>If format is specified and not using predefined format, the format must be specified as a character vector or string scalar composed of symbolic identifiers.</p>
<p
>The format of the input text for representing dates and times, expressed as a character vector or string scalar composed of symbolic identifiers.</p>
<p />
<table border="1">
<tr>
<th>Symbolic Identifier</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td>yyyy</td>
<td>Year in full</td>
<td>1995, 2012</td>
</tr>
<tr>
<td>yy</td>
<td>Year in two digits</td>
<td>89, 01</td>
</tr>
<tr>
<td>QQ</td>
<td>Quarter year using letter Q and one digit</td>
<td>Q1</td>
</tr>
<tr>
<td>mmmm</td>
<td>Month using full name</td>
<td>March, December</td>
</tr>
<tr>
<td>mmm</td>
<td>Month using first three letters</td>
<td>Mar, Dec</td>
</tr>
<tr>
<td>mm</td>
<td>Month in two digits</td>
<td>04, 12</td>
</tr>
<tr>
<td>m</td>
<td>Month using capitalized first letter</td>
<td>M, D</td>
</tr>
<tr>
<td>dddd</td>
<td>Day using full name</td>
<td>Monday, Tuesday</td>
</tr>
<tr>
<td>ddd</td>
<td>Day using first three letters</td>
<td>Mon, Tue</td>
</tr>
<tr>
<td>dd</td>
<td>Day in two digits</td>
<td>06, 21</td>
</tr>
<tr>
<td>d</td>
<td>Day using capitalized first letter</td>
<td>M, T</td>
</tr>
<tr>
<td>HH</td>
<td
>Hour in two digits (no leading zeros when symbolic identifier AM or PM is used)</td>
<td>06, 6 AM</td>
</tr>
<tr>
<td>MM</td>
<td>Minute in two digits</td>
<td>11, 01</td>
</tr>
<tr>
<td>SS</td>
<td>Second in two digits</td>
<td>06, 59</td>
</tr>
<tr>
<td>FFF</td>
<td>Millisecond in three digits</td>
<td>056</td>
</tr>
<tr>
<td>AM or PM</td>
<td>AM or PM inserted in text representing time</td>
<td>5:46:02 PM</td>
</tr>
</table>


</description>
<used_function />
<bibliography />

<examples>
<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data
><![CDATA[dateVector = [2019, 4, 2, 9, 7, 18];
datestr(dateVector)]]>
</example_item_data>
</example_item>

<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data
><![CDATA[dateVector = [2019, 4, 2, 9, 7, 18];
formatOut = 'mm/dd/yy';
datestr(dateVector, formatOut)]]>
</example_item_data>
</example_item>

<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data><![CDATA[datestr(now, 'mmmm dd, yyyy HH:MM:SS.FFF AM')]]>
</example_item_data>
</example_item>

<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data><![CDATA[datestr('06:33 PM','HH:MM')]]>
</example_item_data>
</example_item>

<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data><![CDATA[datestr('06:33','HH:MM PM')]]>
</example_item_data>
</example_item>

<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data
><![CDATA[formatOut = 'dd mmm yyyy';
datestr(datenum('18-05-45','dd-mm-yy',1900),formatOut)
]]>
</example_item_data>
</example_item>

<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data
><![CDATA[datestr(datenum({'09/17/2017';'06/14/1906';'10/29/2014'}, 'mm/dd/yyyy')))]]>
</example_item_data>
</example_item>

<example_item>
<example_item_type>nelson</example_item_type>
<example_item_description />
<example_item_data
><![CDATA[dateStringIn = '5/17/56';
formatOut = 1;
pivotYear = 1900;
datestr(dateStringIn, formatOut, pivotYear)
pivotYear = 2000;
datestr(dateStringIn,formatOut, pivotYear)
]]>
</example_item_data>
</example_item>


</examples>

<see_also>
<see_also_item>
<link linkend="${time}datenum">datenum</link>
</see_also_item>
<see_also_item>
<link linkend="${time}datevec">datevec</link>
</see_also_item>

</see_also>

<history>
<history_item>
<history_version>1.8.0</history_version>
<history_description>initial version</history_description>
</history_item>
</history>

<authors>
<author_item>Allan CORNET</author_item>
</authors>
</xmldoc>
3 changes: 2 additions & 1 deletion modules/time/src/cpp/Calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Calendar::Calendar(double dateserial)
double h = 0.;
double mm = 0.;
double s = 0.;
DateVector(dateserial, y, m, d, h, mm, s);
double ms = 0.;
DateVector(dateserial, y, m, d, h, mm, s, ms);
this->m = static_cast<uint8>(m);
this->y = static_cast<uint64>(y);
}
Expand Down
11 changes: 6 additions & 5 deletions modules/time/src/cpp/DateString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ formatDateTimeString(int Y, int M, int D, int H, int MN, int S, const std::wstri
}
//=============================================================================
std::wstring
epochToDateTimeString(int Y, int M, int D, int H, int MN, int S, bool forceFullFormat,
epochToDateTimeString(int Y, int M, int D, int H, int MN, int S, int MS, bool forceFullFormat,
bool isLocalized, int predefinedFormatOutValue)
{
int month_index = getMonthIndex(M);
Expand All @@ -232,10 +232,10 @@ std::wstring
epochToDateTimeString(
double dateSerial, bool forceFullFormat, bool isLocalized, int predefinedFormatOutValue)
{
double Y, M, D, H, MN, S;
DateVector(dateSerial, Y, M, D, H, MN, S, true);
double Y, M, D, H, MN, S, MS;
DateVector(dateSerial, Y, M, D, H, MN, S, MS, true);
return epochToDateTimeString(
Y, M, D, H, MN, S, forceFullFormat, isLocalized, predefinedFormatOutValue);
Y, M, D, H, MN, S, MS, forceFullFormat, isLocalized, predefinedFormatOutValue);
}
//=============================================================================
static bool
Expand Down Expand Up @@ -305,8 +305,9 @@ DateString(std::vector<double> epochValues, const Dimensions& dimensionsIn, bool
int H = static_cast<int>(epochValues[i + ((j + 3) * rows)]);
int MN = static_cast<int>(epochValues[i + ((j + 4) * rows)]);
int S = static_cast<int>(epochValues[i + ((j + 5) * rows)]);
int MS = 0;
results[l++] = epochToDateTimeString(
Y, M, D, H, MN, S, !noHMNS, isLocalized, predefinedFormatOutValue);
Y, M, D, H, MN, S, MS, !noHMNS, isLocalized, predefinedFormatOutValue);
}
}
} else {
Expand Down
Loading

0 comments on commit 14f63fb

Please sign in to comment.