home contribute faq download

FunctX XQuery Functions

fn:hours-from-duration

The hours in a duration

Google
Webdatypic.com

Description

The fn:hours-from-duration function calculates the hours component of a normalized xs:duration value, as an integer between -23 and 23 (inclusive). This is not necessarily the same as the integer that appears before the H in the value. For example, if the duration is PT1H90M, the function returns 2 rather than 1. This is because 90 minutes is equal to 1.5 hours, and the normalized value is therefore PT2H30M. Likewise, if the duration is PT36H, the result is 12, because the normalized value is P1DT12H.

This is in contrast to the functx:total-hours-from-duration function, which would return 2.5 in the first case, and 36 in the second case.

For a function that returns the total number of hours as a decimal number, see functx:total-hours-from-duration.

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

NameType
$arg xs:duration?
return value xs:integer?

Examples

XQuery ExampleResults
hours-from-duration(
   xs:dayTimeDuration('P1DT5H'))
5
hours-from-duration(
   xs:dayTimeDuration('-PT36H'))
-12
hours-from-duration(
   xs:dayTimeDuration('PT1H90M'))
2
hours-from-duration(
   xs:dayTimeDuration('PT2H59M'))
2
hours-from-duration(
   xs:dayTimeDuration('PT3600S'))
1

See Also

functx:total-hours-from-durationThe total number of hours in a dayTimeDuration

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XQuery Services

Recommended Reading:

XQuery