timezone not supported for datatype "date"
Brought to you by:
pabigot
As defined in http://www.w3.org/TR/xmlschema-2/#date, the date datatype can contain a timezone.
This is currently not supported by pyxb (from binding/datatypes.py):
class date (_PyXBDateOnly_base):
"""U{http://www.w3.org/TR/xmlschema-2/index.html#date}
This class uses the Python C{datetime.date} class as its
underlying representation.
"""_ExpandedName = pyxb.namespace.XMLSchema.createExpandedName('date')
_Lexical_re = re.compile(_PyXBDateTime_base._DateTimePattern('%Y-%m-%d$'))
_Fields = ( 'year', 'month', 'day' )
Since datetime.date does not support timezones, fixing this will require changing the base Python representation for xsd:date to datetime.datetime.
On the topic of using datetime.datetime as the base Python representation, that's pretty much what JAXB does by default - it represents xsd:date as java.util.Calendar's (actually the XMLGregorianCalendar subclass), which is a datetime type with timezone support really.
Ok, I have an interoperability workaround for those trying to communicate with a JAXB implementation.
http://docs.oracle.com/javase/1.5.0/docs/api/javax/xml/datatype/DatatypeFactory.html#newXMLGregorianCalendarDate(int, int, int, int)
In converting to a XmlGregorianCalendar for an xsd:date, the fourth parameter can be set to DatatypeConstants.FIELD_UNDEFINED, which will stop JAXB from generating timezone data. Here's an example:
Calendar c = Calendar.getInstance();
test.setTestDate(DatatypeFactory.newInstance().newXMLGregorianCalendarDate(
Note: You can't just cherry-pick this commit; there's a whole bunch before it that are necessary too. Grab this off the next branch, or ask for a new release.
commit b4efa60561c2bae936d8d9e4e4b029ab723c3550
Author: Peter A. Bigot <pabigot@‌>
Date: Sun Feb 26 13:08:39 2012 -0600