viv:parse-date

parses a string and extracts a date from it

Synopsis

string
viv:parse-date
(date-str, format, timezone, range);
string date-str;
string format;
string timezone;
boolean range;

Arguments

Description

Attempt to parse a string and extract a date from it. The value returned by this function is the extracted date represented as the number of seconds since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).

The optional format string specifies how the date should be parsed. The format specifiers are intended to be compatible with PHP or C strftime() format strings. This function supports the following codes:

In the format string, the space character matches any number of whitespace characters.

Numeric time zone offsets may be in formats such as +0200, -03:30, +12, or -5. Supported time zone abbreviations are: GMT, UT, UTC, Z, WET, WEST, BST, ART, BRT, BRST, NST, NDT, AST, ADT, CLT, CLST, EST, EDT, CST, CDT, MST, MDT, PST, PDT, AKST, AKDT, HST, HAST, HADT, SST, WAT, CET, CEST, MET, MEZ, MEST, MESZ, EET, EEST, CAT, SAST, EAT, MSK, MSD, IST, SGT, KST, JST, GST, NZST, and NZDT.

The default value for the format parameter is the empty string, '""'. If a format string is not specified, the following date formats will be automatically recognized:

Returns

A number of seconds since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC) or 0 if the input argument could not be parsed.

Example

Input Example:

            <process-xsl>
<xsl:variable name="datesec" select="viv:parse-date('06-Nov-94')" />
<datesec><xsl:value-of select="$datesec" /></datesec>
<date><xsl:value-of select="viv:seconds-to-local-date-time($datesec)" /></date>
<timezone><xsl:value-of select="viv:time-zone-name()" /></timezone>
</process-xsl>

Output Example:

            <datesec>784080000</datesec>
            <date>1994-11-05T20:00:00-04:00</date>
            <timezone>EDT</timezone>

Known Issues

The viv:parse-date() function only supports 32-bit dates on 32-bit Linux systems.

Notes

Fast-Indexing and the Date Type

When fast-indexing a field that contains a date, Watson Explorer Engine provides a date type to automate conversion from time values expressed as strings. Fields in a fast index that are declared as being of the date type automatically process their content using viv:parse-date. For this reason, you should not attempt to use viv:parse-date to process fast-indexed variables of type date.

As an example, assume that you had the following content:

    <document xmlns:xi="http://www.w3.org/2003/XInclude">
      <content name="last-update">Thu, 29 Mar 2007 15:20:01 +0100</content>
    </document>

If you fast-index the last-update field as a date (last-update|date), the indexer will automatically fast-index the result of viv:parse-date(content[@name="last-update"]), in which case the value that would be fast indexed would be an integer (1175178001). By default, when used within fast-indexing, viv:parse-date restricts date values to 32-bits. To fast-index dates outside this range, you can use viv:parse-date manually and fast-index the resulting value as an integer. Any searches on this field would have to be expressed as integer values (or converted into integer values before performing the search), so that the comparison would work correctly.