XPath/XQuery subtract-times function

Summary

Returns the xs:dayTimeDuration that corresponds to the elapsed time between the values of $arg2 and $arg1 treated as times on the same date.

Operator Mapping

Defines the semantics of the "-" operator when applied to two xs:time values.

Signature

op:subtract-times(
$arg1 as xs:time,
$arg2 as xs:time
) as xs:dayTimeDuration

Properties

This function is deterministic, context-dependent, and focus-independent. It depends on implicit-timezone.

Rules

The function returns the result of the expression:

op-subtract-dateTimes(
        fn:dateTime(xs:date('1972-12-31'), $arg1),
        fn:dateTime(xs:date('1972-12-31'), $arg2))

Examples

Assume that the dynamic context provides an implicit timezone value of -05:00. Assume, also, that the date components of the reference xs:dateTime correspond to "1972-12-31".

The expression op:subtract-times(xs:time("11:12:00Z"), xs:time("04:00:00")) returns xs:dayTimeDuration("PT2H12M").

The expression op:subtract-times(xs:time("11:00:00-05:00"), xs:time("21:30:00+05:30")) returns xs:dayTimeDuration("PT0S").

The expression op:subtract-times(xs:time("17:00:00-06:00"), xs:time("08:00:00+09:00")) returns xs:dayTimeDuration("P1D").

The expression op:subtract-times(xs:time("24:00:00"), xs:time("23:59:59")) returns xs:dayTimeDuration("-PT23H59M59S").

Notes

Any other reference date would work equally well.