Fix Successor/Predecessor of Date, DateTime, and Time to return null on overflow/underflow (#1734, #1733)#1806
Merged
Conversation
Related IssuesThe following open issues may be related to this PR:
|
|
Formatting check succeeded! |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1806 +/- ##
============================================
+ Coverage 68.76% 68.78% +0.02%
Complexity 1699 1699
============================================
Files 536 536
Lines 30554 30540 -14
Branches 6987 6993 +6
============================================
- Hits 21009 21007 -2
+ Misses 6989 6971 -18
- Partials 2556 2562 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JPercival
approved these changes
Jul 10, 2026
brynrhodes
approved these changes
Jul 10, 2026
antvaset
enabled auto-merge (squash)
July 12, 2026 22:48
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
successor of DateTime(9999,12,31,23,59,59,999) and successor of
@T23:59:59.999threw an EvaluationError (TypeOverflow / "year 10000 falls above the accepted bounds") instead of returning null. Same for predecessor of the minimum DateTime/Time (TypeUnderflow). The current CQL reference is explicit:The engine's own doc comments still said "a run-time error is thrown" - a leftover from an earlier version of the spec.
Fix
SuccessorEvaluator and PredecessorEvaluator now return null when a Date, DateTime, or Time overflows/underflows the representable range:
Also fixes a latent bug in SuccessorEvaluator's Time overflow detection: the MINUTE and SECOND checks compared getMinute() == 23 instead of == 59, so successor of
@T23:59wrapped to@T00:00instead of overflowing, while@T23:23was wrongly treated as overflow.Scope
Limited to the temporal types (Date, DateTime, Time), which is what #1734/#1733 and the conformance tests cover. Numeric types (Integer/Long/Decimal/Quantity) still throw on overflow; per the current spec they should also return null, but that requires reworking the checkMaxDecimal/checkMinDecimal helpers and the internal (value, quantity) overloads (used by interval-boundary computation) to propagate null, and there are no conformance tests for it. Left as a separate, carefully-scoped follow-up.
Tests
Un-doctored the vendored engine-fhir copy of CqlArithmeticFunctionsTest.xml - these had been marked invalid="true" to match the old throwing behavior:
@T23:59:59.999@T00:00:00.000Validated: spotlessApply, :engine:detekt, engine arithmetic + Successor/Predecessor evaluator unit tests, and both vendored suites (R4 + DSTU3) — all green. Full :engine:jvmTest + :engine-fhir:test run completing.
Upstream follow-up
The canonical cql-tests (https://github.com/cqframework/cql-tests) suite still marks these four invalid="true", which now contradicts the current spec. A companion cql-tests PR is needed to change them to expect null; until then the conformance dashboard will report them as failing (same situation as the Exp/Ln fix, #1716).
Fixes #1734
Fixes #1733.