XML technologies / XML Schema / Data type reference / xs:duration
(Excerpt from “XML Schema” by Eric van der Vlist)
Durations
Derived from: xs:anySimpleType
Primitive type: xs:duration
Known subtypes: none
Facets: xs:enumeration, xs:maxExclusive, xs:maxInclusive, xs:minExclusive, xs:minInclusive, xs:pattern, xs:whiteSpace
Definition
<xs:simpleType name="duration" id="duration">
<xs:restriction base="xs:anySimpleType">
<xs:whiteSpace value="collapse" fixed="true"/>
</xs:restriction>
</xs:simpleType>Description
Durations can use all parts of a date-time value, from years to fractional seconds, and are therefore defined as a six-dimensional space. Their ordering relation is only partial: comparing two durations may yield an undefined result because relationships between some date components, such as days per month, are not fixed.
The lexical space of xs:duration is the ISO 8601 format “PnYnMnDTnHnMnS”, whose capital letters are separators omitted when the corresponding component is unused.
Although some durations are indeterminate, they become fixed when a starting date-time is specified. W3C XML Schema uses this property to compare durations. Four date-times were chosen to yield the greatest differences when durations are added. A duration is greater than another if adding it to each of these dates always gives a greater result than adding the other duration to those same dates. They are “1696-09-01T00:00:00Z”, “1697-02-01T00:00:00Z”, “1903-03-01T00:00:00Z” and “1903-07-01T00:00:00Z”.
Restrictions
The lexical space cannot be customized.
Example
Valid values include "PT1004199059S", "PT130S", "PT2M10S", "P1DT2S", "-P1Y" or "P1Y2M3DT5H20M30.123S".
The following values would be invalid: "1Y" (the leading “P” is missing), "P1S" (separator “T” is missing), "P-1Y" (all components must be positive), "P1M2Y" (component order matters: “Y” must precede “M”) or "P1Y-1M" (all components must be positive).
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de