http://zorba.io/modules/datetime

View as XML or JSON.

This module provides functions to retrieve the current dateTime and to parse dates and times.

In contrast to the current-dateTime functions specified in XQuery Functions and Operators, the functions in this module are nondeterministic, that is, they do not return the current dateTime from the dynamic context, but return the actual value.

Dates and times are parsed according to the format given by strptime.

However, date and time values must be "complete."

For a date, the year and either month and day or day of the year must have been parsed.

For a time, the hour must have been parsed. (If either the minute, second, or timezone has not been parsed, they default to 0.)

For a dateTime, the parsing requirements of both date and time must be met.

When a locale is given, it must be of the form {lang}[{sep}{country}[{encoding}]] where {lang} is an ISO 639-1 2-letter or 639-2 3-letter language code, {sep} is either '-' or '_', {country} is an ISO 3166-1 2-letter country code, and {encoding} is any string that begins with a '.'.

The {sep}, {country}, and {encoding} are optional; {encoding} is always ignored.

Examples include: de, en-US, fr_CA, ru_RU.UTF-8.

Function Summary

current-date () as xs:date external

Gets the current date value in Universal time.

current-dateTime () as xs:dateTimeStamp external

Gets the current dateTime value in Universal time.

current-time () as xs:time external

Return the current time value in Universal time.

millis-to-dateTime ($millis as xs:long) as xs:dateTime external

Converts the given number of milliseconds since epoch into its corresponding xs:dateTime.

parse-date ($input as xs:string, $format as xs:string) as xs:date external

Parses a date from a string in the current locale.

parse-date ($input as xs:string, $format as xs:string, $locale as xs:string) as xs:date external

Parses a date from a string in the given locale.

parse-dateTime ($input as xs:string, $format as xs:string) as xs:dateTime external

Parses a dateTime from a string in the current locale.

parse-dateTime ($input as xs:string, $format as xs:string, $locale as xs:string) as xs:dateTime external

Parses a dateTime from a string in the given locale.

parse-time ($input as xs:string, $format as xs:string) as xs:time external

Parses a time from a string in the current locale.

parse-time ($input as xs:string, $format as xs:string, $locale as xs:string) as xs:time external

Parses a time from a string in the given locale.

timestamp () as xs:long external

Gets the the number of milliseconds since epoch.

utc-offset () as xs:long external

Gets the offset of the current timezone from Universal time.

Functions

current-date#0

declare  %an:nondeterministic function datetime:current-date() as xs:date external

Gets the current date value in Universal time.

Note that this function is not stable: it returns the value of the date when the function is invoked.

Parameters

Returns

xs:date
the non-stable date value

current-dateTime#0

declare  %an:nondeterministic function datetime:current-dateTime() as xs:dateTimeStamp external

Gets the current dateTime value in Universal time.

Note that this function is not stable: it returns the value of the date and time when the function is invoked.

Parameters

Returns

xs:dateTimeStamp
the non-stable datetime value

current-time#0

declare  %an:nondeterministic function datetime:current-time() as xs:time external

Return the current time value in Universal time.

Note that this function is not stable: it returns the value of the time when the function is invoked.

Parameters

Returns

xs:time
the non-stable time value

millis-to-dateTime#1

declare  function datetime:millis-to-dateTime($millis as xs:long) as xs:dateTime external

Converts the given number of milliseconds since epoch into its corresponding xs:dateTime.

Parameters

millis as xs:long
The number of milliseconds since epoch.

Returns

xs:dateTime
Returns an xs:dateTime.

parse-date#2

declare  function datetime:parse-date($input as xs:string, $format as xs:string) as xs:date external

Parses a date from a string in the current locale.

Parameters

input as xs:string
The string to parse.
format as xs:string
The format string containing zero or more conversion specifications and ordinary characters. All ordinary characters are matched exactly with the buffer; all whitespace characters match any amount of whitespace in the buffer.

Returns

xs:date
Returns an xs:date.

parse-date#3

declare  function datetime:parse-date($input as xs:string, $format as xs:string, $locale as xs:string) as xs:date external

Parses a date from a string in the given locale.

Parameters

input as xs:string
The string to parse.
format as xs:string
The format string containing zero or more conversion specifications and ordinary characters. All ordinary characters are matched exactly with the buffer; all whitespace characters match any amount of whitespace in the buffer.
locale as xs:string
The locale to use.

Returns

xs:date
Returns an xs:date.

parse-dateTime#2

declare  function datetime:parse-dateTime($input as xs:string, $format as xs:string) as xs:dateTime external

Parses a dateTime from a string in the current locale.

Parameters

input as xs:string
The string to parse.
format as xs:string
The format string containing zero or more conversion specifications and ordinary characters. All ordinary characters are matched exactly with the buffer; all whitespace characters match any amount of whitespace in the buffer.

Returns

xs:dateTime
Returns an xs:dateTime.

parse-dateTime#3

declare  function datetime:parse-dateTime($input as xs:string, $format as xs:string, $locale as xs:string) as xs:dateTime external

Parses a dateTime from a string in the given locale.

Parameters

input as xs:string
The string to parse.
format as xs:string
The format string containing zero or more conversion specifications and ordinary characters. All ordinary characters are matched exactly with the buffer; all whitespace characters match any amount of whitespace in the buffer.
locale as xs:string
The locale to use.

Returns

xs:dateTime
Returns an xs:dateTime.

parse-time#2

declare  function datetime:parse-time($input as xs:string, $format as xs:string) as xs:time external

Parses a time from a string in the current locale.

Parameters

input as xs:string
The string to parse.
format as xs:string
The format string containing zero or more conversion specifications and ordinary characters. All ordinary characters are matched exactly with the buffer; all whitespace characters match any amount of whitespace in the buffer.

Returns

xs:time
Returns an xs:time.

parse-time#3

declare  function datetime:parse-time($input as xs:string, $format as xs:string, $locale as xs:string) as xs:time external

Parses a time from a string in the given locale.

Parameters

input as xs:string
The string to parse.
format as xs:string
The format string containing zero or more conversion specifications and ordinary characters. All ordinary characters are matched exactly with the buffer; all whitespace characters match any amount of whitespace in the buffer.
locale as xs:string
The locale to use.

Returns

xs:time
Returns an xs:time.

timestamp#0

declare  %an:nondeterministic function datetime:timestamp() as xs:long external

Gets the the number of milliseconds since epoch.

Parameters

Returns

xs:long
the said number of milliseconds.

utc-offset#0

declare  %an:nondeterministic function datetime:utc-offset() as xs:long external

Gets the offset of the current timezone from Universal time.

Parameters

Returns

xs:long
the offset in seconds with positive values being east of the prime meridian.