Name

xs:duration

Synopsis

The xs:duration type represents a length of time such as 15 minutes; 2 hours; or 3 years, 7 months, 2 days, 8 hours, 32 minutes, and 12 seconds. It does not have a specific beginning or end, just a length. Durations are represented using the ISO-8601 standard format P n Y n M n DT n H n M n S. n Y gives the number of years, n M the number of months, n D the number of days, n H the number of hours, n M the number of minutes, and n S the number of seconds. The number of years, months, days, hours, minutes, and seconds are all given as nonnegative integers. The number of seconds is a decimal number with as many places after the decimal point as necessary. For example, in this format, 3 years, 7 months, 2 days, 8 hours, 32 minutes, and 12 seconds is written as P3Y7M2DT8H32M12S. Any values that are zero can be omitted. Thus, a duration of 2 years and 2 minutes can be written as P2YT2M. If there are no hours, minutes, or seconds, then the T is omitted. Thus, a duration of two years is written as P2Y. A leading minus sign before the P indicates a negative duration.

Constraining facets that apply to xs:duration are minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, and whiteSpace. However, because the number of days in a month varies from 28 to 31 and the number of days in a year varies from 365 to 366, durations are not always perfectly ordered. For instance, whether P1M is greater than, equal to, or less than P30D depends on which month ...

Get XML in a Nutshell, 3rd Edition 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.