Date/time gaps: month-end durations (Appendix H definition vs formulas), invalid Date components, Today() vs Now() in CalculateAge
Maintainers usually reply within 5 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- xml
- Domain
- testing
Research direction
Start with the proposed XML tests in the issue and the cited Appendix H, Appendix B, and ELM rules. The issue identifies gaps in month-end duration calculations, invalid Date/DateTime components and overflow, and which current-time function CalculateAge uses; compare those rules with the existing tests, including DateTimeAddInvalidYears and DateTimeSubtractInvalidYears. Done means the specification questions are resolved and tests cover the agreed behavior.
Written by the indexing model from the issue text.
Description
While differential testing date operators across engines (the reference engine via @cqframework/cql 5.8.0, and cql-execution 3.3.2 and 4.0.0-beta.1), we found three places where the specification is inconsistent or silent, the engines disagree, and no test in the suite settles the behaviour. Proposed tests follow each point. The points about the specification text would also need an HL7 STU comment.
(The fourth one we found, DurationInDaysA/DurationInDaysAA across offsets, is already covered by #164.)
1. Month end in years between / months between (Appendix H)
Appendix H defines a month (and a year) as ending at the same time of day on the same calendar date, or "at the last calendar date of the ending calendar month, if the same calendar date of the ending month in the ending year does not exist", and notes that the time of day matters. The scenario formulas compare only the day of the month and ignore the time. The two disagree at month end:
| Expression | Definition | Scenario formulas | Reference engine 5.8.0 | cql-execution |
|---|---|---|---|---|
months between @2024-01-31 and @2024-02-29 |
1 | 0 (Scenario 2) | 0 | 1 |
months between @2024-02-29 and @2024-01-31 |
-1 | 0 (Scenario 4) | 0 | -1 |
years between @2012-02-29 and @2014-02-28 (YearsBetweenLeapYearDatesEquals2) |
2 | 1 (Scenario 3) | 2 | 2 |
years between @2000-02-29T12:00:00.000Z and @2001-02-28T09:00:00.000Z |
0 | 0 | 1 | 0 |
For years, Example 3.b in Appendix H follows the definition although it is listed under Scenario 3, and so does the existing test. Nothing covers months. The reference engine's behaviour is reported in cqframework/clinical_quality_language#1978.
Proposed tests (values from the definition; cql-execution passes all of them today):
<test name="MonthsBetweenMonthEnd" version="1.5">
<capability code="duration-between"/>
<expression>months between @2024-01-31 and @2024-02-29</expression>
<output>1</output>
</test>
<test name="MonthsBetweenMonthEnd30" version="1.5">
<capability code="duration-between"/>
<expression>months between @2024-03-31 and @2024-04-30</expression>
<output>1</output>
</test>
<test name="MonthsBetweenAddOneMonth" version="1.5">
<capability code="duration-between"/>
<expression>months between @2024-01-31 and (@2024-01-31 + 1 month)</expression>
<output>1</output>
</test>
<test name="MonthsBetweenMonthEndNegative" version="1.5">
<capability code="duration-between"/>
<expression>months between @2024-02-29 and @2024-01-31</expression>
<output>-1</output>
</test>
<test name="MonthsBetweenMonthEndDateTime" version="1.5">
<capability code="duration-between"/>
<expression>months between @2024-01-31T10:00:00.000Z and @2024-02-29T10:00:00.000Z</expression>
<output>1</output>
</test>
<test name="MonthsBetweenMonthEndEarlierTime" version="1.5">
<capability code="duration-between"/>
<expression>months between @2024-01-31T10:00:00.000Z and @2024-02-29T09:00:00.000Z</expression>
<output>0</output>
</test>
<test name="YearsBetweenLeapDayEarlierTime" version="1.5">
<capability code="duration-between"/>
<expression>years between @2000-02-29T12:00:00.000Z and @2001-02-28T09:00:00.000Z</expression>
<output>0</output>
</test>
<test name="YearsBetweenLeapDayNextDayEarlierTime" version="1.5">
<capability code="duration-between"/>
<expression>years between @2000-02-29T12:00:00.000Z and @2001-03-01T09:00:00.000Z</expression>
<output>1</output>
</test>
The same applies to age: CalculateAgeInMonthsAt(@2024-03-31, @2024-04-30) is 1 by the definition (0 in the reference engine). This could go into the clinical operator tests proposed in #157.
2. Invalid components in the Date and DateTime selectors
Appendix B (Date, DateTime) gives the rule for missing components only. It does not say what Date(2023, 2, 29), Date(2023, 13, 1) or Date(2023, 1, 32) yield. The reference engine throws; cql-execution returns a non-existent date that later turns into NaN (cqframework/cql-execution#414). The translator rejects the equivalent literal @2023-02-29 ("Invalid date-time input").
Proposed tests, following the reference engine and the treatment of literals (an error). If the work group prefers null, the same tests with <output>null</output>:
<test name="DateInvalidLeapDay" version="1.5">
<expression invalid="true">Date(2023, 2, 29)</expression>
</test>
<test name="DateInvalidMonth" version="1.5">
<expression invalid="true">Date(2023, 13, 1)</expression>
</test>
<test name="DateInvalidDay" version="1.5">
<expression invalid="true">Date(2023, 1, 32)</expression>
</test>
<test name="DateTimeInvalidLeapDay" version="1.5">
<expression invalid="true">DateTime(2023, 2, 29, 0, 0, 0, 0, 0)</expression>
</test>
Related gap: the Author's Guide (Date/Time arithmetic) states the out-of-range error only for years, which DateTimeAddInvalidYears and DateTimeSubtractInvalidYears test. Month and day overflow (@9999-12-15 + 1 month, @9999-12-31 + 1 day, @0001-01-01 - 1 day) are covered by neither text nor tests. The reference engine throws; cql-execution returns null, also for years (cqframework/cql-execution#413).
3. Today() or Now() in CalculateAge for a DateTime birth date
The specification gives three different rules:
- Appendix B, Age: "for AgeInYears and AgeInMonths, the birthDate is specified as a Date and Today() is used to obtain the current date; whereas with the other precisions, birthDate is specified as a DateTime, and Now() is used". The rule depends on the precision.
- Appendix B, CalculateAge: "as of the current date", shorthand for
CalculateAgeInXXXAt"passing the current date for the asOf argument". Read literally, a "current date" gives no time of day forCalculateAgeInHours(DateTime). - ELM,
CalculateAge: "For the Date overload, the calculation is performed using Today() … For the DateTime overload, the calculation is performed using Now()". The rule depends on the type.
The engines follow different rules. The reference engine follows the type; cql-execution follows the precision and applies the Age note to CalculateAge (for years and months it truncates a DateTime birth date to a Date). Evaluated at 2025-02-28T10:00:00.000Z, CalculateAgeInMonths(@2024-02-29T23:59:59.999Z) is 11 in the reference engine and 12 in cql-execution.
A fixed expected value is impossible without a fixed evaluation time, but a relational test works under the ELM rule:
<test name="CalculateAgeInMonthsDateTimeUsesNow" version="1.5">
<expression>CalculateAgeInMonths(@2024-02-29T23:59:59.999Z) = CalculateAgeInMonthsAt(@2024-02-29T23:59:59.999Z, Now())</expression>
<output>true</output>
</test>
Under the precision rule, this is false only on days when the age changes, so it is a weak check. The main point is to align the three texts.
- Dominant language
- No language data
- Stars
- 8
- Forks
- 9
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cqframework/cql-tests
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
cqframework/cql-tests#182 ·
Maintainers usually reply within 5 days
-
CqlComparisonOperatorsTest: NotEquivalentNullNull marks `null !~ null` invalid, where the specification gives it as falsePossibly taken @leftonmars claimed this 13 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 78/100
cqframework/cql-tests#172 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
cqframework/cql-tests#170 ·
Maintainers usually reply within 5 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
cqframework/cql-tests#158 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
cqframework/cql-tests#157 ·
Maintainers usually reply within 5 days
All issues in cqframework/cql-tests
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 91/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
hermes hooks doctor smoke test never checks the hook exit code — a crashing hook (exit=1) renders ✓ "ran clean" and "All shell hooks look healthy"Possibly taken @cestercian claimed this today. Opencomp/cli P2 type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NousResearch/hermes-agent#162259 · 1 comment ·
Maintainers usually reply within 1 day