fn:adjust-date-to-timezone

Adjusts an xs:date value to a specific timezone, or to no timezone at all; the result is the date in the target timezone that contains the starting instant of the supplied date.

Signatures

fn:adjust-date-to-timezone($arg as xs:date?) as xs:date?
fn:adjust-date-to-timezone(
    $arg as xs:date?, 
    $timezone as xs:dayTimeDuration?
) as xs:date?

Properties

The one-argument form of this function is deterministic, context-dependent, and focus-independent. It depends on implicit timezone.

The two-argument form of this function is deterministic, context-independent, and focus-independent.

Rules

If $timezone is not specified, then the effective value of $timezone is the value of the implicit timezone in the dynamic context.

If $arg is the empty sequence, then the function returns the empty sequence.

If $arg does not have a timezone component and $timezone is the empty sequence, then the result is the value of $arg.

If $arg does not have a timezone component and $timezone is not the empty sequence, then the result is $arg with $timezone as the timezone component.

If $arg has a timezone component and $timezone is the empty sequence, then the result is the local value of $arg without its timezone component.

If $arg has a timezone component and $timezone is not the empty sequence, then the function returns the value of the expression:

Error Conditions

A dynamic error is raised [ERRFODT0003] if $timezone is less than -PT14H or greater than PT14H or is not an integral number of minutes.

Examples

Assume the dynamic context provides an implicit timezone of -05:00 (-PT5H0M).

let $tz-10 := xs:dayTimeDuration("-PT10H")

The expression fn:adjust-date-to-timezone(xs:date("2002-03-07")) returns xs:date("2002-03-07-05:00").

The expression fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00")) returns xs:date("2002-03-07-05:00"). ($arg is converted to xs:dateTime("2002-03-07T00:00:00-07:00"). This is adjusted to the implicit timezone, giving "2002-03-07T02:00:00-05:00". ).

The expression fn:adjust-date-to-timezone(xs:date("2002-03-07"), $tz-10) returns xs:date("2002-03-07-10:00").

The expression fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00"), $tz-10) returns xs:date("2002-03-06-10:00"). ($arg is converted to the xs:dateTime "2002-03-07T00:00:00-07:00". This is adjusted to the given timezone, giving "2002-03-06T21:00:00-10:00". ).

The expression fn:adjust-date-to-timezone(xs:date("2002-03-07"), ()) returns xs:date("2002-03-07").

The expression fn:adjust-date-to-timezone(xs:date("2002-03-07-07:00"), ()) returns xs:date("2002-03-07").