This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi-xmlbeans.git
The following commit(s) were added to refs/heads/trunk by this push:
new a76e00e5 treat a zero timezone offset as Z in the GDate canonical form
(#161)
a76e00e5 is described below
commit a76e00e575c2ecb9ec3d3ac4b68059327789c11f
Author: aizu-m <[email protected]>
AuthorDate: Wed Nov 11 11:57:33 2026 +0530
treat a zero timezone offset as Z in the GDate canonical form (#161)
---
src/main/java/org/apache/xmlbeans/GDate.java | 5 ++
.../java/org/apache/xmlbeans/GDateBuilder.java | 10 +++
...ZeroTimezoneIdentityConstraintValidateTest.java | 87 ++++++++++++++++++++++
3 files changed, 102 insertions(+)
diff --git a/src/main/java/org/apache/xmlbeans/GDate.java
b/src/main/java/org/apache/xmlbeans/GDate.java
index b854e99b..2ee67120 100644
--- a/src/main/java/org/apache/xmlbeans/GDate.java
+++ b/src/main/java/org/apache/xmlbeans/GDate.java
@@ -878,6 +878,11 @@ public final class GDate implements GDateSpecification,
java.io.Serializable {
(hasTimeZone() && getTimeZoneSign() != 0 && hasTime() &&
((hasDay() == hasMonth() && hasDay() == hasYear())));
+ // +00:00 and -00:00 are the same timezone as Z
+ if (!needNormalize && hasTimeZone() && getTimeZoneSign() != 0) {
+ needNormalize = (getTimeZoneHour() == 0 && getTimeZoneMinute() ==
0);
+ }
+
if (!needNormalize && getFraction() != null && getFraction().scale() >
0) {
BigInteger bi = getFraction().unscaledValue();
needNormalize = (bi.mod(GDateBuilder.TEN).signum() == 0);
diff --git a/src/main/java/org/apache/xmlbeans/GDateBuilder.java
b/src/main/java/org/apache/xmlbeans/GDateBuilder.java
index 2b0f7527..5d4622b2 100644
--- a/src/main/java/org/apache/xmlbeans/GDateBuilder.java
+++ b/src/main/java/org/apache/xmlbeans/GDateBuilder.java
@@ -643,6 +643,11 @@ public final class GDateBuilder implements
GDateSpecification, java.io.Serializa
} else {
// No timezone, or incomplete date.
_normalizeTimeAndDate();
+
+ // +00:00 and -00:00 are the same timezone as Z
+ if (hasTimeZone() && _tzh == 0 && _tzm == 0) {
+ _tzsign = 0;
+ }
}
// remove trailing zeros from fractional seconds
@@ -1486,6 +1491,11 @@ public final class GDateBuilder implements
GDateSpecification, java.io.Serializa
(hasTimeZone() && getTimeZoneSign() != 0 && hasTime() &&
((hasDay() == hasMonth() && hasDay() == hasYear())));
+ // +00:00 and -00:00 are the same timezone as Z
+ if (!needNormalize && hasTimeZone() && getTimeZoneSign() != 0) {
+ needNormalize = (getTimeZoneHour() == 0 && getTimeZoneMinute() ==
0);
+ }
+
if (!needNormalize && getFraction() != null && getFraction().scale() >
0) {
BigInteger bi = getFraction().unscaledValue();
needNormalize = (bi.mod(TEN).signum() == 0);
diff --git
a/src/test/java/misc/checkin/ZeroTimezoneIdentityConstraintValidateTest.java
b/src/test/java/misc/checkin/ZeroTimezoneIdentityConstraintValidateTest.java
new file mode 100644
index 00000000..ffcde9e4
--- /dev/null
+++ b/src/test/java/misc/checkin/ZeroTimezoneIdentityConstraintValidateTest.java
@@ -0,0 +1,87 @@
+/* Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package misc.checkin;
+
+import org.apache.xmlbeans.GDate;
+import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+public class ZeroTimezoneIdentityConstraintValidateTest {
+
+ // the six date types without a time, each with a Z, +00:00 and -00:00
form of the same value
+ private static final String[][] SAME = {
+ {"date", "2000-01-01Z", "2000-01-01+00:00", "2000-01-01-00:00"},
+ {"gYearMonth", "2000-01Z", "2000-01+00:00", "2000-01-00:00"},
+ {"gYear", "2000Z", "2000+00:00", "2000-00:00"},
+ {"gMonthDay", "--01-01Z", "--01-01+00:00", "--01-01-00:00"},
+ {"gDay", "---01Z", "---01+00:00", "---01-00:00"},
+ {"gMonth", "--01Z", "--01+00:00", "--01-00:00"}
+ };
+
+ private static List<String> unique(String type, String a, String b) throws
Exception {
+ String xsd =
+ "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' " +
+ "xmlns:t='urn:t' targetNamespace='urn:t'
elementFormDefault='qualified'>" +
+ " <xs:element name='u'>" +
+ " <xs:complexType><xs:sequence>" +
+ " <xs:element name='d' type='xs:" + type + "'
maxOccurs='unbounded'/>" +
+ " </xs:sequence></xs:complexType>" +
+ " <xs:unique name='uniq'><xs:selector xpath='t:d'/><xs:field
xpath='.'/></xs:unique>" +
+ " </xs:element>" +
+ "</xs:schema>";
+ XmlObject doc = XmlBeans.loadXsd(new
XmlObject[]{SchemaDocument.Factory.parse(xsd)})
+ .parse("<t:u xmlns:t='urn:t'><t:d>" + a + "</t:d><t:d>" + b +
"</t:d></t:u>", null, null);
+ List<XmlError> errors = new ArrayList<>();
+ doc.validate(new XmlOptions().setErrorListener(errors));
+ return
errors.stream().map(XmlError::getErrorCode).collect(Collectors.toList());
+ }
+
+ @Test
+ void zeroOffsetIsTheSameTimezoneAsZ() throws Exception {
+ for (String[] row : SAME) {
+ for (int i = 2; i < row.length; i++) {
+ GDate z = new GDate(row[1]);
+ GDate other = new GDate(row[i]);
+ assertEquals(z, other, row[1] + " " + row[i]);
+ assertEquals(z.hashCode(), other.hashCode(), row[1] + " " +
row[i]);
+ assertEquals(row[1], other.canonicalString());
+
assertEquals(Collections.singletonList("cvc-identity-constraint.4.1"),
+ unique(row[0], row[1], row[i]), row[1] + " " + row[i]);
+ }
+ }
+ }
+
+ @Test
+ void otherTimezonesStayDistinct() throws Exception {
+ assertNotEquals(new GDate("2000-01-01Z"), new
GDate("2000-01-01+01:00"));
+ assertNotEquals(new GDate("2000-01-01Z"), new GDate("2000-01-01"));
+ assertEquals("2000-01-01+01:00", new
GDate("2000-01-01+01:00").canonicalString());
+ assertEquals(Collections.emptyList(), unique("date", "2000-01-01Z",
"2000-01-01"));
+ assertEquals(Collections.emptyList(), unique("gYear", "2000Z",
"2001+00:00"));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]