XSD dateTime offset serialization discards IANA timezone identifier context
0 reputation · 26 Apr 2022, 08:47 UTC
0 reputation · 26 Apr 2022, 08:47 UTC
Preserve geographic timezone context when exchanging xs:dateTime values across XML documents and services.
The XML Schema specification defines dateTime, date, and time types with an optional offset suffix (±hh:mm or Z) but provides no mechanism to attach a named IANA timezone identifier such as America/New_York. Schema validation only verifies lexical format and offset range (±14:00); it cannot confirm that an offset matches historical rules for any geographic zone. XSD 1.1 introduces xs:dateTimeStamp (which requires an offset) and assertions, yet still lacks a facility to bind a value to a timezone database entry. Major parsers (Xerces, Saxon, .NET System.Xml) expose the offset as a string or numeric minutes and perform no DST-aware conversion unless the calling code uses a separate timezone library. Consequently, a value generated in Europe/Paris summer time (+02:00) serialises as +02:00, and a consumer cannot reliably reconstruct the original zone without out-of-band metadata.
xs:dateTime?dateTime values?32775 reputation · 26 Apr 2022, 20:16 UTC
It is impossible to reliably reconstruct a specific IANA timezone identifier (e.g., Europe/Paris) from a standalone xs:dateTime value. The XSD dateTime type is designed to represent a specific point in time using a UTC offset, but it does not store the geographic rules (DST transitions, historical shifts) associated with a named zone. Because multiple IANA zones often share the same offset, the offset is an ambiguous indicator of geographic context.
To preserve the original IANA zone, you must move the timezone identifier out of the xs:dateTime value and into a companion metadata field.
The most robust pattern is to wrap the xs:dateTime in a complex type that includes a string attribute for the IANA zone ID. This ensures the point-in-time is preserved via the offset, while the geographic context is preserved via the identifier.
<xs:complexType name="ZonedDateTime">
<xs:simpleContent>
<xs:extension base="xs:dateTime">
<xs:attribute name="timezone" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Example Instance:
<eventTime timezone="Europe/Paris">2026-10-14T15:00:00+02:00</eventTime>
XSD 1.1 assertions cannot enforce offset-to-zone consistency. While an assertion can verify that a string matches a specific regex pattern, it cannot perform a dynamic lookup against the IANA Time Zone Database (tzdb) to verify if +02:00 is the correct offset for Europe/Paris on a given date. This validation must occur in the application layer using libraries such as java.time (Java) or pytz (Python).
There are no widely adopted XSD extensions that embed IANA identifiers directly into the xs:dateTime lexical representation. Any attempt to append a zone ID to the value (e.g., 2026-10-14T15:00:00+02:00[Europe/Paris]) will cause a schema validation failure, as it violates the XSD lexical space for dateTime.
xs:dateTime and a string attribute.ZonedDateTime object correctly reflects the intended geographic zone.Diagnostic Detail Required: Are you targeting future-dated events? If so, the offset in the xs:dateTime should be treated as a "snapshot" and the IANA zone as the "source of truth," as government-mandated DST changes may render the serialized offset incorrect by the time the event occurs.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.