XSLT and XPath function reference in alphabetical order

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 5, translated from German)

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

fn:adjust-dateTime-to-timezone

Category:

Date functions – timezone

Origin:

XPath 2.0

Return value:

A timestamp value xs:dateTime.

Call/Arguments:

fn:adjust-dateTime-to-timezone($dateTime?, $timezone?)

$dateTime:

Optional. A timestamp value xs:dateTime. If no value is passed on, the function returns an empty sequence.

$timezone:

Optional. The second argument is a timezone indication of xs:dayTimeDuration type. If the argument is omitted, the implicit timezone indication in the evaluation context is used. If the empty sequence is passed on as second argument, an existing timezone indication from the timestamp value passed on as the first argument is removed.

The timezone indication must not fall below a value of -PT14H and must not exceed a value of PT14H. Otherwise the error »Invalid timezone value« (err:FODT0003) will be reported.

Purpose of use:

The function adjusts a timestamp value xs:dateTime to a timezone indication which is passed on as second argument or which is implicit from the context. The original timezone is taken into account regarding the daytime part of the result and, where applicable, the date is adjusted (see example 6).

Example 1 - without passing on a timezone correction:

fn:adjust-dateTime-to-timezone(

xs:dateTime("2007-07-07T10:00:00")

)

Results in: 2007-07-07T10:00:00-05:00.

For the purpose of this example, an implicit timezone indication of -5:00 was assumed, accordingly -PT5H0M. Since no second argument has been passed on, an implicit timezone indication is connected with the timestamp value and outputted.

Example 2 - without passing on a timezone correction:

fn:adjust-dateTime-to-timezone(

xs:dateTime("2007-07-07T10:00:00-07:00")

)

Results in: 2007-03-07T12:00:00-05:00.

For the purpose of this example, an implicit timezone indication of -5:00 was assumed, accordingly -PT5H0M. If a timestamp value is passed on with timezone indication, but without timezone correction, the timezone indication is rejected and replaced by the implicit timezone indication. The daytime part is adjusted by subtracting the original timezone factor and adding the new one. In this case, the time results from 10:00:00 – (-07:00) + (-05:00) to 12:00:00.

Example 3 - with passing on a timezone correction:

fn:adjust-dateTime-to-timezone(

xs:dateTime("2007-07-07T10:00:00"),

xs:dayTimeDuration("-PT10H")

)

Results in: 2007-07-07T10:00:00-10:00.

If a correction factor is passed on as second argument in the form of a timezone indication, this factor is included into the result. A possible existing implicit timezone value of the evaluation context is not taken into account. An adjustment to the daytime part is not required.

Example 4 - with passing on a timezone correction:

fn:adjust-dateTime-to-timezone(

xs:dateTime("2007-03-07T10:00:00-07:00"),

xs:dayTimeDuration("-PT10H")

)

Results in: 2007-03-07T07:00:00-10:00.

If the timestamp value already has a timezone indication in the form of a factor, it will be replaced by the timezone factor passed on. A possible existing implicit timezone value of the evaluation context is not taken into account. The adjustment to the daytime part is made analogous to example 2.

Example 5 - with passing on an empty sequence:

fn:adjust-dateTime-to-timezone(

xs:dateTime("2007-03-07T10:00:00-07:00"),

()

)

Results in: 2007-03-07T10:00:00.

If the timestamp value has a timezone indication and an empty sequence is passed on to the function as second argument, the timezone indication is removed from the timestamp value. A possible existing implicit timezone value of the evaluation context is not taken into account. The daytime part remains unchanged.

Example 6 - with date correction:

fn:adjust-dateTime-to-timezone(

xs:dateTime("2007-07-07T10:00:00-07:00"),

xs:dayTimeDuration("PT10H")

)

Results in: 2007-07-08T03:00:00+10:00.

If the correction of the daytime indication results in a value greater than 24 for the hours indication when including both timezone corrections, the date indication is adjusted accordingly. Here, the number of hours results in 10:00:00 – (-07:00) + 10:00 equals 27 hours, which is converted into 03:00:00 of the following day. Therefore, the day part of the date is increased by 1.

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

fn:adjust-dateTime-to-timezone($arg as xs:dateTime?)

as xs:dateTime?

fn:adjust-dateTime-to-timezone($arg as xs:dateTime?,

$timezone as xs:dayTimeDuration?)

as xs:dateTime?

   

<< back next >>

 

 

 


Copyright © Galileo Press, Bonn 2008
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSLT 2.0 & XPath 2.0" is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.


Galileo Press, Rheinwerkallee 4, 53227 Bonn, Germany