views:

34

answers:

1

When parsing dates and times from XML documents into JodaTime objects, I use a common set of conversion utilities, generally using the parsers and formatters supplied by org.joda.time.format.ISODateTimeFormat.

This works fine in the majority of cases, but this time I'm seeing documents with the xs:date value of the format 2010-08-19Z. This is a perfectly valid xs:date value, but none of the standard ISODateTimeFormat-generated LocalDate parsers I've tried will accept it. The closest I can find is ISODateTimeFormat.dateParser(), which will accept the rather odd-looking 2010-08-19TZ, but not 2010-08-19Z (note the T).

This is all quite irritating, since both Joda and XML Schema are supposed to strictly adhere to the ISO date/time formatting rules, but either one of them isn't, or the spec is fuzzy.

Before I admit defeat and hand-roll a custom format, can anyone point me at a ISODateTimeFormat-sourced parser that will read that value?

+1  A: 

I believe that according to ISO-8601, 'Z' is part of the time value. The 'T' separator is used only to create combined date/time values. A strict reading of this implies that 'Z' cannot appear after a date without a time value, which can be empty, thus the "odd-looking" 2010-08-18TZ.

This appears to be a slight impedance mismatch between the definitions of xs:date and ISO-8601.

EDIT: I found a copy of ISO 8601. It does not define the concept of a "time-zoned date" such as is defined in the XML Schema Datatypes spec.

Rather than writing one from scratch, how about a simple wrapper that converts xs:date instances with timezones into corresponding ISO-8601 values (i.e. just insert the 'T') and then use the existing ISODateTimeFormat.dateParser()?

Jim Garrison
So the specs don't quite match up. Great :(
skaffman
I think ISO-8601 was defined quite a few years ago, long before XML Schemas, and they probably didn't think of dates as rigorously as the XML Schema spec does.
Jim Garrison