#102 timezone not supported for datatype "date"

PyXB 1.1.4
Binding model
PyXB 1.1.2

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):


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' )


  • Peter A. Bigot

    Peter A. Bigot - 2011-08-26
    • status changed from new to assigned

    Since datetime.date does not support timezones, fixing this will require changing the base Python representation for xsd:date to datetime.datetime.

  • Peter A. Bigot

    Peter A. Bigot - 2011-09-09
    • milestone changed from PyXB 1.1.3 to PyXB 1.1.4
  • Nathan Robertson

    • cc nathanrobertson added

    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();

    c.get(Calendar.MONTH) + 1,

  • Peter A. Bigot

    Peter A. Bigot - 2012-02-26
    • status changed from assigned to closed
    • resolution set to fixed

    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

    trac/102: Timezone support for xsd:date types


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks