The Duration Types
XQuery uses three types to represent durations of time:
xs:duration
,
xs:yearMonthDuration
, and xs:dayTimeDuration
.
The xs:duration
type represents a duration of time expressed as a number of years, months, days, hours, minutes, and seconds. Its format is PnYnMnDTnHnMnS
, where P
is a literal value that starts the expression, nY
is the number of years followed by a literal Y
, and so on where M
refers to months, D
refers to days, H
refers to hours, the second M
refers to minutes, and S
refers to seconds. T
is a literal value that separates the date and time. The numbers are all integers, except the number of seconds, which may be a decimal number. It is also possible to have a negative duration by preceding the P
with a minus sign (−
).
The xs:duration
type is not totally ordered, meaning that values of this type cannot always be compared. For example, if you try to determine whether the xs:duration
value P1M
is greater than or less than the xs:duration
value P30D
, it is ambiguous. Months may have 28, 29, 30, or 31 days. So, is 30 days less than a month, or not?
The yearMonthDuration and dayTimeDuration Types
Because xs:duration
is not ordered, XQuery defines two types that are derived from duration: xs:yearMonthDuration
and xs:dayTimeDuration
.
By ensuring that month and day components never appear in the same duration, the ambiguity is eliminated.
Values of type xs:yearMonthDuration
can only specify years and months, and they are represented as PnYnM
. Values ...
Get XQuery now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.