Skip to content

Commit 4c4bac3

Browse files
committed
[bugfix] Allow comparison of xs:dateTime and xs:dateTimeStamp
Closes eXist-db/exist#5478
1 parent 3830bbf commit 4c4bac3

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

exist-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@
678678
<includes>
679679
<include>project-suppression.xml</include>
680680
<include>src/test/java/org/exist/xquery/ImportFromPkgTest.java</include>
681+
<include>src/test/java/org/exist/xquery/value/DateTimeTypesTest.java</include>
681682
<include>src/test/resources-filtered/org/exist/xquery/import-from-pkg-test.conf.xml</include>
682683
</includes>
683684
</licenseSet>
@@ -766,6 +767,7 @@
766767
<include>src/main/java/org/exist/xquery/functions/fn/FunUriCollection.java</include>
767768
<include>src/main/java/org/exist/xquery/functions/system/GetUptime.java</include>
768769
<include>src/main/java/org/exist/xquery/functions/system/Shutdown.java</include>
770+
<include>src/main/java/org/exist/xquery/value/AbstractDateTimeValue.java</include>
769771
<include>src/main/java/org/exist/xquery/value/Type.java</include>
770772
<include>src/main/java/org/exist/xslt/EXistURIResolver.java</include>
771773
<include>src/main/resources-filtered/org/exist/system.properties</include>
@@ -889,6 +891,8 @@
889891
<exclude>src/main/java/org/exist/xquery/functions/fn/FunUriCollection.java</exclude>
890892
<exclude>src/main/java/org/exist/xquery/functions/system/GetUptime.java</exclude>
891893
<exclude>src/main/java/org/exist/xquery/functions/system/Shutdown.java</exclude>
894+
<exclude>src/main/java/org/exist/xquery/value/AbstractDateTimeValue.java</exclude>
895+
<exclude>src/test/java/org/exist/xquery/value/DateTimeTypesTest.java</exclude>
892896
<exclude>src/main/java/org/exist/xquery/value/Type.java</exclude>
893897
<exclude>src/main/java/org/exist/xslt/EXistURIResolver.java</exclude>
894898
<exclude>src/main/resources-filtered/org/exist/system.properties</exclude>

exist-core/src/main/java/org/exist/xquery/value/AbstractDateTimeValue.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -45,6 +69,7 @@
4569
import java.util.regex.Pattern;
4670

4771
/**
72+
* @author <a href="mailto:[email protected]">Adam Retter</a>
4873
* @author wolf
4974
* @author <a href="mailto:[email protected]">Piotr Kaminski</a>
5075
* @author ljo
@@ -363,7 +388,7 @@ public boolean compareTo(Collator collator, Comparison operator, AtomicValue oth
363388
}
364389

365390
public int compareTo(Collator collator, AtomicValue other) throws XPathException {
366-
if (other.getType() == getType()) {
391+
if (other.getType() == getType() || other.getType() == Type.DATE_TIME_STAMP && getType() == Type.DATE_TIME || other.getType() == Type.DATE_TIME && getType() == Type.DATE_TIME_STAMP) {
367392
// filling in missing timezones with local timezone, should be total order as per XPath 2.0 10.4
368393
final int r = getImplicitCalendar().compare(((AbstractDateTimeValue) other).getImplicitCalendar());
369394
if (r == DatatypeConstants.INDETERMINATE) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
package org.exist.xquery.value;
22+
23+
import org.exist.test.ExistXmldbEmbeddedServer;
24+
import org.junit.ClassRule;
25+
import org.junit.Test;
26+
import org.xmldb.api.base.XMLDBException;
27+
28+
import static org.junit.Assert.assertEquals;
29+
30+
/**
31+
* @author <a href="mailto:[email protected]">Adam Retter</a>
32+
*/
33+
public class DateTimeTypesTest {
34+
35+
@ClassRule
36+
public static final ExistXmldbEmbeddedServer server = new ExistXmldbEmbeddedServer(true, true, true);
37+
38+
@Test
39+
public void compareDateTimeWithDateTimeStamp() throws XMLDBException {
40+
final String result = server.executeOneValue("xs:dateTime('2024-10-07T09:56:00+01:00') <= current-dateTime()");
41+
assertEquals("true", result);
42+
}
43+
44+
@Test
45+
public void compareDateTimeStampWithDateTime() throws XMLDBException {
46+
final String result = server.executeOneValue("current-dateTime() <= xs:dateTime('2024-10-07T09:56:00+01:00')");
47+
assertEquals("false", result);
48+
}
49+
}

0 commit comments

Comments
 (0)