fn:hours-from-duration function

The fn:hours-from-duration function returns the hours component of a duration value.

Syntax

Read syntax diagramSkip visual syntax diagramfn:hours-from-duration( duration-value)
duration-value
The duration value from which the hours component is to be extracted.

duration-value is an empty sequence or is a value that has one of the following types: xs:dayTimeDuration, xs:duration, or xs:yearMonthDuration.

Returned value

The return value depends on the type of duration-value:

  • If duration-value is of type xs:dayTimeDuration or is of type xs:duration, the returned value is of type xs:integer, and is a value between -23 and 23, inclusive. The value is the hours component of duration-value cast as xs:dayTimeDuration. The value is negative if duration-value is negative.
  • If duration-value is of type xs:yearMonthDuration, the returned value is of type xs:integer and is 0.
  • If duration-value is an empty sequence, the returned value is an empty sequence.

The hours component of duration-value cast as xs:dayTimeDuration is the integer number of hours computed as ((S mod 86400) idiv 3600). The value S is the total number of seconds of duration-value cast as xs:dayTimeDuration to remove the days and months component. The value 86400 is the number of seconds in a day, and 3600 is the number of seconds in an hour.

Example

The following function returns the hours component of the duration 126 hours.

fn:hours-from-duration(xs:dayTimeDuration("PT126H"))

The returned value is 6. When calculating the total number of hours in the duration, 126 hours is converted to 5 days and 6 hours. The duration is equal to P5DT6H which has an hours component of 6 hours.