On 23/09/2011 14:03, Christophe Marchand wrote:
> I have a strange behavior with JAXP date comparisons :
> Here is a sample code :
> DatatypeFactory df = DatatypeFactory.newInstance();
> XMLGregorianCalendar d1 = df.newXMLGregorianCalendar(s1);
> XMLGregorianCalendar d2 = df.newXMLGregorianCalendar(s2);
> ret = (d1.compare(d2) <= 0)?Boolean.TRUE:Boolean.FALSE;
> logger.debug("funcDateBefore("+d1.toXMLFormat()+","+d2.toXMLFormat()+") ->
> Comparing 2011-09-23T11:17:21.815+02:00 to 2011-09-24 responds that
> first date is *not* before second date.
> Comparing 2011-09-23T11:17:21.815+02:00 to 2011-09-25 responds that
> first date is before second date.
> I think there is a bug here ; timezone is not so different that
> difference is more than 12 hours.
I suspect that this is following the XSD semantics for date/time
comparison, rather than the XPath semantics, which are different. the
XSD rules give a result of "interdeterminate ordering" if the range of
possible dateTime values for 2011-09-24 overlaps the specific dateTime
> Implementation I have is
> Is there a Saxon replacement for this, and how could I use it ?
I would be inclined to use Saxon's net.sf.saxon.value.DateTimeValue
class, which implements both the XPath and XSD semantics, depending
whether you call getXPathComparable() or getSchemaComparable() to get
the object that you use for comparison.