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:hours-from-time

Category:

Value extraction from time values, date values and duration

Origin:

XPath 2.0

Return value:

An integer of xs:integer type which corresponds to the value of the hours component of the xs:time time value put into normalised form and passed on.

Call/Arguments:

fn:hours-from-time($time)

$time:

Optional. A daytime indication of xs:time type which may include the timezone indication. If no value is passed on (empty sequence), the function returns the empty sequence.

Purpose of use:

If there is an explicit or an implicit timezone indication, the xs:time time value passed on is accordingly normalised. This means, the timezone difference is subtracted, whereby in case of reaching or exceeding a hours value of 24 or in case of falling below 0, the number 24 is accordingly subtracted or added.

The return value is a xs:integer integer between (inclusive) 0 and 23 which corresponds to the hours component of the normalised value.

Note: All following examples imply an implicit timezone indication of -5:00 (Eastern Standard Time).

Example 1 - hours from time indication:

fn:hours-from-time(

xs:time("11:23:00")

)

results in: 16.

The number of hours of 16 results from the normalisation of the value with 11-(-5:00). The (negative!) timezone factor is subtracted, absolutely seen added. Since here no threshold value is exceeded, the result value can be outputted directly.

Example 2 - hours from time indication:

fn:hours-from-time(

xs:time("21:23:00")

)

results in: 2.

The number of hours of 2 results from the normalisation of the value with 21-(-5:00). The (negative!) timezone factor is subtracted, absolutely seen added. The interim result is 26, which means it exceeds the threshold of 24 hours. Therefore, the actual result is calculated from 26 - 24.

Example 3 - hours from time indication:

fn:hours-from-time(

xs:time("19:00:00")

)

results in: 0.

The number of hours of 0 results from the normalisation of the value with 19-(-5:00). The canonical value for midnight is 00:00:00, therefore in this example not 24, but 0 (accordingly 24 - 24) is outputted.

Example 4 - hours from time indication with explicit timezone:

fn:hours-from-time(

xs:time("1:23:00+05:00")

)

results in: 20.

In this case, the implicit timezone is not used because the example shows an explicit indication. By its subtraction, the threshold falls below 0, which means the value 24 has to be added to the interim result: 1 - (+5:00) results in -4; -4 + 24 leads to the final result of 20.

Function definition:

XPath 1.0:

The function is not available.

XPath 2.0:

fn:hours-from-time($arg as xs:time?) as xs:integer?

   

<< 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