This document is also available in these non-normative formats: .
Copyright © 2005 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark, document use and software licensing rules apply.
This document discusses some of the problems encountered when working with the date
, time
, and dateTime
values from XML Schema when those value include (or omit) time zone offsets. Many W3C technologies rely on date and time types. Examples of these include the XQuery 1.0 and XPath 2.0 Functions and Operators specifications, since these are the basis for XQuery and XSLT processing of date/time values, but the concepts presents affect any datetime processing.
This document is an editors' copy that has no official standing.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This is the first public Working Draft of the Internationalization Core Working Group for review by interested parties. Publication as Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document has been produced as part of the W3C Internationalization Activity, following the procedures set out for the W3C Process.
Your feedback is welcome, especially regarding the open issues identified in this document. Please send your comments to the public mailing list (public-i18n-core@w3.org), an archived mailing list dedicated to discussion associated with the Internationalization Core Working Group. See W3C mailing list and archive usage guidelines.
As of this publication, the Working Group expects this document to become a W3C Working Group Note.
1 Working With Time Zones
1.1 Background
1.2 Identifying Time Zones and Zone Offsets
1.3 Incremental versus Field-Based Time
1.4 Guidelines
1.4.1 Working with Field-Based Dates and Times
1.4.1.1 Working with Date and Time Values that Require a Time Zone (and not a zone offset)
1.4.2 Comparing Times
1.5 Recommendations for XQuery / XSLT
A References (Non-Normative)
Time-related data is a common requirement for many applications. XML Schema provides a variety of data types for dates and times, such as date
, time
, and dateTime
. These data types follow internationally friendly formats defined by ISO 8601 and can be used to address a variety of differing date or time applications.
The date
, time
, and dateTime
types can either include or omit the time zone offset. The presence (or absence) of the offset means that the data value must be handled differently for certain kinds of operations. In addition, the particular application and source of the date and time values affects how dates and times with different time zones or zone offsets should be handled, as well as how to handle values that lack any time zone or zone offset indication.
Note:
Users and implementers of languages or specifications which handle time-related data should take the following recommendations into account even if time-zone-sensitive data is rarely used. Sooner or later some data will be affected by the issues described. Some examples of these include XQuery, XPath, and XSLT.
There are three main applications of date, time, or dateTime data types in applications.
XML Schema follows the ISO 8601 standard for its lexical representation. Date and time values in ISO 8601 are field-based using the definitions above and can indicate (or omit) the zone offset from UTC. A zone offset is not the same thing as a time zone, and the difference can be important. XML Schema only supports zone offset, but, confusingly, calls it timezone, see for example Section 3.2.8.1, lexical representation in that document.
Although ISO 8601 is expressed in terms of the Gregorian calendar, it can be used to represent values in any calendar system. The presentation of date and time values to end users using different calendar and timekeeping systems is separate from the lexical representation.
What is a "zone offset"? A zone offset is the difference in hours and minutes between a particular time zone and UTC. In ISO 8601, the particular zone offset can be indicated in a date or time value. The zone offset can be Z
for UTC or it can be a value "+" or "-" from UTC. For example, the value 08:00-08:00
represents 8:00 AM in a time zone 8 hours behind UTC, which is the equivalent of 16:00Z (8:00 plus eight hours). The value 08:00+08:00
represents the opposite increment, or midnight (08:00 minus eight hours).
What is a "time zone"? A time zone is an identifier for a specific location or region which translates into a combination of rules for calculating the UTC offset. For example, when a website maintaining a group calendar in the United States schedules a recurring meeting for 08:00 Pacific Time
, it is referring to what is sometimes known as wall time (so called because that is the time shown "on the clock (or calendar) on the wall"). This is not equivalent to either 08:00-08:00
or 08:00-07:00
, because Pacific Time
does not have a fixed offset from UTC; instead, the offset changes during the course of the year. As mentioned before, XML Schema only supports zone offset, and it does not make the terminological distinction between zone offset and time zone. So a wall time expressed as an XML Schema time
value, must choose which zone offset to use. This may have the unintended effect of causing a scheduled event to shift by an hour (or more) when wall time changes to or from Daylight/Summer time.
To complicate matters, the rules for computing when daylight savings takes effect may be somewhat complex and may change from year to year or from location to location. In the United States, the state of Indiana, for example, does not follow daylight savings time, but this will change in April 2006. See: http://www.mccsc.edu/time.html. The Northern and Southern hemispheres perform Daylight/Summer Time adjustments during opposing times during the year (corresponding to seasonal differences in the two hemispheres).
To capture these situations, a calendar system must use an ID for the time zone. The most definitive reference for dealing with wall time is the TZ database (also known as the "Olson time zone database"), which is used by systems such as various commercial UNIX operating systems, Linux, Java, CLDR, ICU, and many other systems and libraries. In the TZ database, "Pacific Time" is denoted with the ID America/Los_Angeles
. The TZ database also supplies aliases among different IDs; for example, Asia/Ulan Bator
is equivalent to Asia/Ulaanbaatar
. From these alias relations, a canonical identifier can be derived. The Common Locale Data Repository can be used to provide a localized form for the IDs: see Appendix J in UTR #35.
If the two types are mixed, then the interpretation of the zone offset is not adequately specified in XML Schema. In XQuery 1.0 and XPath 2.0 Functions and Operators, the interpretation is implementation-defined and is based on an implicit zone offset. This is usually either UTC or local time. The presence or absence of the zone offset in the XML Schema representation may not be indicative of the original data's intention because of the confusion described above. Proper comparisons or processing rely on normalizing all date and time values into zone offset-independent (or zone offset-dependent) forms and never mixing the two in a particular operation.
If the dates are not fixed (such as <T01:30, TZID>
— notice that the date value is omitted) then in some sense, neither is 'before' the other, since each refers to a repeating, interleaved set of points in time. The simplest comparison mechanism where the dates may not be fully specified is simply to put both in canonical form, then order them first by time then by TZID (alphabetical, caseless order). The Olson database does not maintain a fixed canonical form; however, CLDR does provide such a form (see: ).
(It is also possible to have a looser comparison, whereby <time0, TZID0>
is compared to <time1, TZID1>
over some interval of time: if one consistently has a smaller offset during that period, it is considered to be less than the other value. However, there are cases where this mechanism results in a partial ordering.)
Unfortunately, XML Schema date and time types do not provide for Olson IDs, so most time operations cannot use TZIDs directly. Time zone identification in the date and time types relies entirely on time zone offset from UTC. It is up to the document designer to keep the TZID in a separate data field from the time value.
If possible, make sure that data always contains an explicit zone offset.
If you have data that includes implicit and fixed explicit zone offsets, before applying any date- or time-sensitive operations adjust the zone offset of the implicit data to UTC with the functions for zone offset adjustment, cf. http://www.w3.org/TR/xpath-functions/#timezone.functions.
If you have data that contains both implicit and fixed explicit timezones and you do not want to adjust the data subset which already has a zone offset, make sure that you recognize this data subset, for example via the component extraction functions http://www.w3.org/TR/xpath-functions/#d1e4771.