users@jaxb.java.net

Confused about required format for "DatatypeFactory.newXMLGregorianCalendar(String)" with date/time with timezone

From: KARR, DAVID (ATTSI) <"KARR,>
Date: Wed, 24 Feb 2010 11:10:37 -0800

DatatypeFactory isn't strictly JAXB-related, but I figure it has a
strong correlation to use of JAXB.

I'm calling "DatatypeFactory.newXMLGregorianCalendar(String)" and I'm
storing the result in an element with a restriction on "xs:datetime".
I'm having trouble getting the formatting correct.

The schema excerpt is as follows:

    <xs:restriction base='xs:dateTime'>
      <xs:pattern value='.+T.+Z'/>
    </xs:restriction>

(which seems odd, as this pattern seems to ignore the "date" portion,
correct?)

From the documentation in our schema:

  - T is a fixed character, indicating the time section
  - Z is a fixed character, indicating UTC time zone

I've looked at <http://www.w3.org/TR/xmlschema-2/#dateTime-order> (which
is mentioned in the javadoc for this function), but it hasn't helped me
solve this problem.

I've tried giving it a formatted date/time value of
"2010-05-19T01:00:00-08:00", but when schema validation is done, this
fails to validate. It appears I'm formatting the timezone value
incorrectly, but I'm not sure what it should be.

I tried simply replacing the "-08:00" portion with "Z", and that
appeared to pass validation. Is that what's intended here?