Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTC only datetimes #12

Closed
wants to merge 1 commit into from
Closed

Conversation

krischer
Copy link

This changes forces all datetimes in a StationXML file to end with a Z. This explicitly marks them as being in UTC which (according to the SEED standard) must be given in any case.

Motivation

It is currently possible to have non-UTC datetimes in a StationXML file (e.g. 2013-01-01T00:00:00+07:00). While this is not allowed according to the SEED standard the schema does not prevent it and any XML file with this would still validate just fine.

The forced Z at the end explicitly marks a time as being UTC and as a consequence also forbids setting any time zone.

While the schema alone will never be enough to define the semantics of StationXML it should be sufficient to define its syntax. This change is a small step in that direction.

StationXML would additionally gain a more consistent datetime representation.

Potential Impact

Little. Existing implementations would have to be changed to add a Z at the end and remove time zones (if any). Considering implementations would have to at least up the version number if they update to a new StationXML version this is really no big problem.

Other Possibilities

It would also be possibly (with a more complex regular expression) to not have the Z at the end and still disallow timezones. I personally prefer the current approach as it is more explicit.

All datetimes are now forced to end with a `Z` which disables the
possibility to set a time zone and also explicitly marks every datetime
as being UTC.
@crotwell
Copy link
Collaborator

This sounds like a good idea in general to me. However, I do not think a pattern is the right way to do this. See this section of the xschema docs:
https://www.w3.org/TR/xmlschema11-2/#rf-explicitTimezone

A better way would be to use a fixed=true, value=Z explicitTimezone.

@crotwell
Copy link
Collaborator

crotwell commented Oct 26, 2016

Take this comment back, looks like the explicitTimezone allows specifying if the timezone is required or not, but not what it actually is (ie Z). So if the timezone is going to be required, it might be useful to set

<xs:restriction base="xs:dateTime">
    <xs:explicitTimezone value="required"/>
</xs:restriction>

but the pattern would still be needed to check for just Z.

@krischer
Copy link
Author

I also tried this but xmllint somehow complains if explicitTimezone is used as a restriction. After your comment I also searched around a bit for in-schema ways to fix the time zone but I guess the pattern is required.

The current implementation is pretty save as it combines all the default date time restrictions that make sure that its a valid date time with the pattern that asserts it ends with Z.

@crotwell
Copy link
Collaborator

Also sent to fdsn email list, but just to preserve for future reference in case of wanting full regex for datetime:

<xs:simpleType name="UTCDateTimeType">
    <xs:annotation>
        <xs:documentation>
UTC only datetime type,
timezone of Z is optional but strongly recommended.
        </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:dateTime">
        <xs:pattern
value="-?([1-9][0-9]{3,}|0[0-9]{3})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\.[0-9]+)?|(24:00:00(\.0+)?))Z?"/>
    </xs:restriction>
</xs:simpleType>

@krischer
Copy link
Author

I does not appear to have arrived on the list.

It is not really needed here as the base xs:dateTime already guarantees all these things and has even stronger contraints, e.g. no February 29th on non-leap years and other things impossible to express in regular expressions.

@krischer
Copy link
Author

Thread on the mailing list: http://www.fdsn.org/message-center/thread/464/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Require DateTimes to be in UTC (...Z)
3 participants