From 8f2b022b06701a69524560651ae038a04533f69e Mon Sep 17 00:00:00 2001 From: Ryan Baumann Date: Thu, 8 Oct 2015 14:45:59 -0400 Subject: [PATCH] Correctly handle BCE leap years in call to GregorianCalendar isLeapYear(), according to XSD 1.0 Second Edition spec --- .../com/thaiopensource/datatype/xsd/DateTimeDatatype.java | 3 +++ mod/xsd-datatype/test/xsdtest.xml | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/mod/xsd-datatype/src/main/com/thaiopensource/datatype/xsd/DateTimeDatatype.java b/mod/xsd-datatype/src/main/com/thaiopensource/datatype/xsd/DateTimeDatatype.java index 42daa4e82..b09f6f618 100644 --- a/mod/xsd-datatype/src/main/com/thaiopensource/datatype/xsd/DateTimeDatatype.java +++ b/mod/xsd-datatype/src/main/com/thaiopensource/datatype/xsd/DateTimeDatatype.java @@ -252,6 +252,9 @@ private static Date createDate(GregorianCalendar cal, int tzOffset, boolean nega month -= 1; cal.set(year, month, day, hours, minutes, seconds); cal.set(Calendar.MILLISECOND, milliseconds); + if (negative) { + year = -(year - 1); + } checkDate(cal.isLeapYear(year), month, day); // for GCJ return cal.getTime(); } diff --git a/mod/xsd-datatype/test/xsdtest.xml b/mod/xsd-datatype/test/xsdtest.xml index 5bbba48da..1a22e085b 100644 --- a/mod/xsd-datatype/test/xsdtest.xml +++ b/mod/xsd-datatype/test/xsdtest.xml @@ -214,6 +214,12 @@ 1886-12-01 1886-12-01Z +0004-02-29 +-0001-02-29 +-0257-02-29 +0003-02-29 +-0257-02-30 +-0258-02-29 1066-12-31 1900-01-01