$Sir DateChk: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:$Sir_DateChk}} <span class="pageSubtitle">Check if datetime matches format</span> <p class="warn"><b>Note:</b> This $function require the <var class="product">...")
 
m (link repair)
 
(11 intermediate revisions by the same user not shown)
Line 2: Line 2:
<span class="pageSubtitle">Check if datetime matches format</span>
<span class="pageSubtitle">Check if datetime matches format</span>


<p class="warn"><b>Note:</b> This $function require the <var class="product">[[Media:Ul2krNew.pdf|Sir2000 User Language Tools]]</var> product. </p>  
<p class="warn"><b>Note:</b> This $function require the <var class="product">[[Sir2000 User Language Tools]]</var> product. </p>  
 
<p>
<p>The <var>$Sir_DateChk</var> function expects a datetime format string and a datetime value string.
The <var>$Sir_DateChk</var> function expects a datetime format string and a datetime value string.
It accepts an optional <var>CENTSPAN</var> value, and an optional error control string.
It accepts an optional <var>[[Datetime string formats#Using CENTSPAN|CENTSPAN]]</var> value, and an optional error control string.
<var>$Sir_DateChk</var> returns the value 1 if the datetime value is valid and
<var>$Sir_DateChk</var> returns the value 1 if the datetime value is valid and
matches the provided format, otherwise the value 0 is returned. </p>
matches the provided format, otherwise the value 0 is returned. </p>
<p>
<p>
The <var>$Sir_DateChk</var> function is similar to the <var>$DATECHK</var> standard SOUL function.
The <var>$Sir_DateChk</var> function is similar to the <var>[[$DateChk]]</var> standard SOUL function.
However, the <var>$DateChk</var> function does not support the specification of a <var>[[CENTSPLT parameter|CENTSPLT]]</var>
However, the <var>$DateChk</var> function does not support the specification of a <var>CENTSPAN</var> argument. </p>
or <var>[[DEFCENT parameter|DEFCENT]]</var> argument. </p>


===Syntax===
==Syntax==
<p class="syntax"><span class="term">%tst</span> = $Sir_DateChk(<span class="term">fmt, dat, span, errctl</span>)
<p class="syntax"><span class="term">%tst</span> = $Sir_DateChk(<span class="term">fmt</span>, <span class="term">dat</span>, [<span class="term">span</span>], [<span class="term">errctl</span>])
</p>
</p>
Where:
Where:
<table>
<table>
<tr><th>%tst</th>
<td>Set to 1 if <var class="term">dat</var> matches <var class="term">fmt</var>; otherwise set to 0.</td></tr>
<tr><th>fmt</th>
<tr><th>fmt</th>
<td>Datetime format string. Refer to [[Datetime string formats]] for an explanation of valid datetime formats and valid dates. Strict matching is used for <i>fmt</i>.</td></tr>
<td>Datetime format string. Refer to [[Datetime string formats]] for an explanation of valid datetime formats and valid dates. [[Datetime string formats#Strict and non-strict format matching|Strict matching]] is used for <var class="term">fmt</var>.</td></tr>


<tr><th>dat</th>
<tr><th>dat</th>
Line 28: Line 30:


<tr><th>errctl</th>
<tr><th>errctl</th>
<td>Optional error control string, refer to [[Datetime string formats#Datetime error handling|Datetime error handling]].</td></tr>
<td>Optional error control string, refer to [[The Sir2000 APPDATE command#Error handling control with DATE ERR|Error handling control with DATE_ERR]].</td></tr>
 
<tr><th>%tst</th>
<td>Set to 1 if <var class="term">dat</var> matches <var class="term">fmt</var>; otherwise set to 0.</td></tr>
</table>
</table>
<p>
<p>
Line 38: Line 37:
Note that the request is not cancelled, even though an optional error control
Note that the request is not cancelled, even though an optional error control
string was provided: </p>
string was provided: </p>
<p class="code">%x = $sir_datechk('DAY Month, YYYY', -
<p class="code">%x = $sir_datechk('DAY Month, YYYY', '30 February, 1997',,'CANCEL')
                  '30 February, 1997',,'CANCEL')
if %x = 1 then
if %x = 1 then
   print 'Good'
   print 'Good'
Line 47: Line 45:
</p>
</p>


===Error conditions===
==Error conditions==
<p>
<p>
<var>$Sir_DateChk</var> returns a value of 0 if any of the following
<var>$Sir_DateChk</var> returns a value of 0 if any of the following
Line 64: Line 62:
</ul>
</ul>
<p>
<p>
For more information about error handling, see the <var>[[APPDATE command|APPDATE]]</var> command
For more information about error handling, see [[Sir2000 User Language Tools $functions#Errors in datetime $functions|Errors in datetime $functions]]. </p>
and see <var>[[Sir_Date_Err]]</var>. </p>


[[Category:$Functions|$Sir_DateChg]]
[[Category:Sir2000 User Language Tools $functions]]
[[Category:Sir2000 User Language Tools $functions]]

Latest revision as of 22:54, 8 February 2018

Check if datetime matches format

Note: This $function require the Sir2000 User Language Tools product.

The $Sir_DateChk function expects a datetime format string and a datetime value string. It accepts an optional CENTSPAN value, and an optional error control string. $Sir_DateChk returns the value 1 if the datetime value is valid and matches the provided format, otherwise the value 0 is returned.

The $Sir_DateChk function is similar to the $DateChk standard SOUL function. However, the $DateChk function does not support the specification of a CENTSPAN argument.

Syntax

%tst = $Sir_DateChk(fmt, dat, [span], [errctl])

Where:

%tst Set to 1 if dat matches fmt; otherwise set to 0.
fmt Datetime format string. Refer to Datetime string formats for an explanation of valid datetime formats and valid dates. Strict matching is used for fmt.
dat Datetime string.
span Optional CENTSPAN value, default is -50. Refer to Using CENTSPAN.
errctl Optional error control string, refer to Error handling control with DATE_ERR.

The following fragment prints the string Bad, since February cannot have thirty days. Note that the request is not cancelled, even though an optional error control string was provided:

%x = $sir_datechk('DAY Month, YYYY', '30 February, 1997',,'CANCEL') if %x = 1 then print 'Good' else print 'Bad' end if

Error conditions

$Sir_DateChk returns a value of 0 if any of the following errors are detected:

  • fmt is not a valid datetime format.
  • dat is not a valid date, or does not match fmt, or is outside of range permitted for fmt. Note that these cases are always treated as if an error control string of IGNORE had been specified.
  • span is not a valid CENTSPAN value.

For more information about error handling, see Errors in datetime $functions.