ruvim
ruvim

Reputation: 8554

How to negate duration in XPath

If $d and $e are durations, the expression $d lt -$e does not work since in XPath3 only op:numeric-unary-minus is defined and no unary-minus for other types. In other words, unary minus (negation) is not applicable to a duration but to a number only.

How to solve this issue and get the negation of a duration?

Upvotes: 1

Views: 47

Answers (1)

ruvim
ruvim

Reputation: 8554

Multiplication by a number is defined for duration in XPath3, so we can just multiply by -1 to change the sign of a duration:

$d lt ( -1 * $e )

NB: unary minus can be used in lexical representation of a duration, i.g.

xs:dayTimeDuration("-PT50S")

Upvotes: 1

Related Questions