Skip to content

GH-4299: Compare xsd:date values by their starting instants - #4435

Open
0z5a wants to merge 1 commit into
apache:mainfrom
0z5a:gh-4299-date-compare
Open

0z5a wants to merge 1 commit into
apache:mainfrom
0z5a:gh-4299-date-compare

Conversation

@0z5a

@0z5a 0z5a commented Nov 19, 2026

Copy link
Copy Markdown

GitHub issue resolved #4299

Pull request Description:

I started from #4299 and checked it against the code. =, !=, < and > on two xsd:date values go through XSDFuncOp.compareDateTime, which (unless StrictDateTimeFO is set) uses compareDateTimeXSD and getXMLGregorianCalendarXSD. That method fixes up xsd:time and xsd:dateTime (hour 24), but leaves xsd:date as a calendar with no time fields. XMLGregorianCalendar.compare then normalizes the timezone on the date fields only, which ends up comparing the UTC calendar day instead of the day's starting instant. So '2026-01-01+01:00'^^xsd:date = '2026-01-01+02:00'^^xsd:date is true, while subtracting the two gives PT1H.

getXMLGregorianCalendarFO, which ORDER BY uses through compareDateTimeFO, already sets the time to 00:00:00 for dates. This change adds the same block to getXMLGregorianCalendarXSD, so the operators compare starting instants, as F&O defines for op:date-equal and op:date-less-than. Comparing a date without a timezone to one with a timezone within 14 hours is still indeterminate (testCompare17).

How I found it

I followed NVCompare.sameValueAs and NVCompare.compare for VSPACE_DATE down to the two getXMLGregorianCalendar* methods and saw that only the F&O one handles dates. I then checked the JDK behaviour on its own: for the pairs in the issue, compare gives EQUAL on the date-only calendars and GREATER / LESSER once hour, minute and second are set to 0.

Where this can show up in practice

Data that records dates with timezone offsets, for example event days from several regions, or the same day exported by systems in different zones. A FILTER(?d1 = ?d2) or FILTER(?d < ?cutoff) can then match pairs whose days start at different times, and the result can differ from ORDER BY on the same values, which already uses starting instants. This is my estimate beyond the report in #4299.

Testing

  • New tests in TestXSDFuncOp: testCompare24 and testCompare25 (the two pairs from the issue) and testSameDate_4. Without the change to XSDFuncOp, all three fail. With it, TestXSDFuncOp passes.
  • mvn -pl jena-arq test (Java 21, with jena-iri3986, jena-langtag, jena-base and jena-core installed first): 16895 tests, 0 failures, 0 errors, 1 skipped.
  • Not run: the other modules (TDB, Fuseki), and the build with StrictDateTimeFO set.

  • Tests are included.
  • Documentation change and updates are provided for the Apache Jena website
  • Commits have been squashed to remove intermediate development commit messages.
  • Key commit messages start with the issue number (GH-xxxx)

By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.


See the Apache Jena "Contributing" guide.

getXMLGregorianCalendarXSD left xsd:date values without a time, so
XMLGregorianCalendar.compare normalized the timezone on the date fields
only and compared the UTC calendar day. Set the time to 00:00:00 for
dates, as getXMLGregorianCalendarFO already does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xsd:date equality normalizes to the UTC calendar day, contradicting date subtraction: a = b is true while a - b is PT1H

1 participant