fn:months-from-duration

Returns the number of months in a duration.

Signature

fn:months-from-duration($arg as xs:duration?) as xs:integer?

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

If $arg is the empty sequence, the function returns the empty sequence.

Otherwise, the function returns an xs:integer representing the months component in the value of $arg. Given that a duration is a ($months, $seconds) tuple, the result is the value of ($months mod 12).

If $arg is a negative duration then the result will be negative.

If $arg is an xs:dayTimeDuration the function returns 0.

Examples

The expression fn:months-from-duration(xs:yearMonthDuration("P20Y15M")) returns 3.

The expression fn:months-from-duration(xs:yearMonthDuration("-P20Y18M")) returns -6.

The expression fn:months-from-duration(xs:dayTimeDuration("-P2DT15H0M0S")) returns 0.