вівторок, 20 грудня 2011 р.

Poperly reading xs:date from xml

Actually, correctly read xs:date from XML isn't easy task.
Let's investigate how to do it whith famous JodaTime
There is built in formatter for xs:datetime:
ISODateTimeFormat.dateTimeParser()

However, there is not formatter for xs:date - hopefully we can build next custom formatter to handle this situation:
new DateTimeFormaterBuilder().append(null, new DateTimeParser[]{
    DateTimeFormat.forPattern("yyyy'-'MM'-'ddZ").getParser(),
    DateTimeFormat.forPattern("yyyy'-'MM'-'dd").getParser()
}).toFormatter()

It works correcly in the most of cases, but according to standart, xs:date can have leading '-'. To hadle this situation, just add two more formatter with leading '-', and it'll work properly