hours-from-duration
The hours in a duration
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.
Parameters |
Description |
---|---|
arg:numeric() |
Examples
XPath |
Results |
---|---|
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 |