fn:adjust-dateTime-to-timezone function

The fn:adjust-dateTime-to-timezone function adjusts an xs:dateTime value to a specific time zone, or removes the time zone component from the value.

Syntax

Read syntax diagramSkip visual syntax diagramfn:adjust-dateTime-to-timezone( dateTime-value, timezone-value)
dateTime-value
The dateTime value that is to be adjusted.

dateTime-value is of type xs:dateTime, or is an empty sequence.

timezone-value
A duration that represents the time zone to which dateTime-value is to be adjusted.

timezone-value can be an empty sequence or a single value of type xs:dayTimeDuration between -PT14H and PT14H, inclusive. The value can have an integer number of minutes and must not have a seconds component. If timezone-value is not specified, the default value is PT0H, which represents UTC.

Returned value

The returned value is either a value of type xs:dateTime or is an empty sequence depending on the types of input values. If dateTime-value is not an empty sequence, the returned value is of type xs:dateTime. The following table describes the possible returned values:

Table 1. Types of input values and returned value for fn:adjust-dateTime-to-timezone
dateTime-value timezone-value Returned value
dateTime-value that contains a time zone component An explicit value, or no value specified (duration of PT0H) The dateTime-value adjusted to the time zone represented by timezone-value. The returned value contains the time zone component represented by timezone-value.
dateTime-value that contains atime zone component An empty sequence The dateTime-value with no time zone component.
dateTime-value that does not contain a time zone component An explicit value, or no value specified (duration of PT0H)

The dateTime-value with a time zone component. The time zone component is the time zone represented by timezone-value. The date and time components are not adjusted to the time zone.

dateTime-value that does not contain a time zone component An empty sequence The dateTime-value.
An empty sequence An explicit value, empty sequence, or no value specified An empty sequence.

Examples

In the following examples, the variable $tz is a duration of -10 hours, defined as xs:dayTimeDuration("-PT10H").

The following function adjusts the dateTime value of March 7, 2009 at 10 a.m. in the UTC-7 time zone to the time zone specified by time zone-value of -PT10H.

fn:adjust-dateTime-to-timezone(xs:dateTime("2009-03-07T10:00:00-07:00"), $tz)

The returned dateTime value is 2009-03-07T07:00:00-10:00.

The following function adjusts the dateTime value for March 7, 2009 at 10 am. The dateTime-value does not have a time zone component, and the function specifies a timezone-value of -PT10H.

fn:adjust-dateTime-to-timezone(xs:dateTime("2009-03-07T10:00:00"), $tz)

The returned dateTime is 2009-03-07T10:00:00-10:00.

In the following function adjusts the dateTime value for June 4, 2009 at 10 a.m. in the UTC-7 time zone. Without a timezone-value specified, the function uses the default time zone value of PT0H.

fn:adjust-dateTime-to-timezone(xs:dateTime("2009-06-04T10:00:00-07:00"))

The returned dateTime value is 2009-06-04T17:00:00Z, which is the dateTime value adjusted to UTC.

The following function removes the time zone component from the dateTime value for March 7, 2009 at 10 a.m. in the UTC-7 time zone. The timezone-value value is the empty sequence.

fn:adjust-dateTime-to-timezone(xs:dateTime("2009-03-07T10:00:00-07:00"), ())

The returned dateTime value is 2009-03-07T10:00:00.