adjust-date-to-timezone function

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

Syntax

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

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

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

timezone-value can be an empty sequence or a single value of type xdt: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:date or an empty sequence depending on the parameters that are specified. If date-value is not an empty sequence, the returned value is of type xs:date. The following table describes the possible returned values:

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

When adjusting date-value to a different time zone, date-value is treated as a dateTime value with time component 00:00:00. The returned value contains the timezone component represented by timezone-value. The following function calculates the adjusted date value:

xs:date(fn:adjust-dateTime-to-timezone(xs:dateTime(date-value),timezone-value))

Examples

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

The following function adjusts the date value for May 7, 2002 in the UTC+1 time zone. The function specifies a timezone-value of -PT10H.

fn:adjust-date-to-timezone(xs:date("2002-05-07+01:00"), $tz) 

The returned date value is 2002-05-06-10:00. The date is adjusted to the UTC-10 time zone.

The following function adds a timezone component to the date value for March 7, 2002 without a timezone component. The function specifies a timezone-value of -PT10H.

fn:adjust-date-to-timezone(xs:date("2002-03-07"), $tz)

The returned value is 2002-03-07-10:00. The timezone component is added to the date value.

The following function adjusts the date value for February 9, 2002 in the UTC-7 time zone. Without a timezone-value specified, the function uses the default timezone-value PT0H.

fn:adjust-date-to-timezone(xs:date("2002-02-09-07:00"))

The returned date is 2002-02-09Z, the date is adjusted to UTC.

The following function removes the timezone component from the date value for May 7, 2002 in the UTC-7 time zone. The timezone-value is an empty sequence.

fn:adjust-date-to-timezone(xs:date("2002-05-07-07:00"), ())

The returned value is 2002-05-07.