Clarify truncating or rounding of fractions past milliseconds (Time, DateTime, ToTime, ToDateTime)

Open
#199 0 comments 0 reactions 0 assignees View on GitHub

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
Documentation
Clarity
Clearly specified
Activity status
Active
Domain
testing-qa

Research direction

Start with tests/cql/CqlTypesTest.xml and the TimeMillisParsing case, then check how this test suite represents DateTime literals and ToTime/ToDateTime conversions. The issue asks maintainers to decide truncation, rounding, and overflow behavior before adding cases for the listed boundary inputs; done means the expected behavior is clarified and covered by tests.

Written by the indexing model from the issue text.

Description

Question

When a Time or DateTime value carries more fraction digits than milliseconds, is it reduced by truncating or by rounding? And does the same rule hold for ToTime(String) and ToDateTime(String)? The specification says such a value is quantized but not how, and the suite has no case where the two readings differ. Engines can then disagree on results that change the second, the day or the year.

This continues #166, which proposes millisecond from @2017-12-21T02:00:00.1234 → 123 and notes that truncating and rounding both give 123 there.

What the specification says

CQL 1.5.3:

  • Language Semantics, Table 5‑G, Millisecond: "999 milliseconds is the maximum required precision. Note that many operations require the ability to compute the “next” or “prior” instant, and these semantics depend on the step-size of 1 millisecond, so systems that support more than millisecond precision will need to quantize to the millisecond to achieve these semantics."
  • Appendix B, Types, DateTime: "CQL supports date and time values in the range @0001-01-01T00:00:00.0 to @9999-12-31T23:59:59.999 with a 1 millisecond step size." Time has the same sentence for "@T00:00:00.0 to @T23:59:59.999".
  • Appendix B, ToTime and ToDateTime: the string is expected in the form hh:mm:ss.fff and YYYY-MM-DDThh:mm:ss.fff(Z|((+|-)hh:mm)).

"Quantize" does not say whether the extra digits are dropped or rounded.

What the tests say

tests/cql/CqlTypesTest.xml, test TimeMillisParsing, is the only case with more than three fraction digits:

<expression>@T23:59:59.10000</expression>
<output>@T23:59:59.100</output>

.10000 gives .100 under either reading.

Cases that are undecided

Expression Truncate Round
@T10:30:00.1239 @T10:30:00.123 @T10:30:00.124
@T23:59:59.9996 @T23:59:59.999 @T00:00:00.000, or an error, since there is no 24:00:00
@2020-12-31T23:59:59.9996Z @2020-12-31T23:59:59.999Z @2021-01-01T00:00:00.000Z
@9999-12-31T23:59:59.9996Z @9999-12-31T23:59:59.999Z outside the required range

And for the string conversions, where "not formatted correctly" gives null:

Expression Reduced like a literal Rejected
ToTime('10:30:00.1239') @T10:30:00.123 or .124 null
ToDateTime('2020-12-31T23:59:59.9996Z') as the literal above null

Two sub-questions:

  1. Literals: truncate or round? If round, what is the result when rounding leaves the day (Time) or the required range (DateTime)?
  2. ToTime(String), ToDateTime(String) and convert: is a string with more than three fraction digits reduced like a literal, or is the result null?

The answer also settles, by analogy, values that reach CQL from a data model, such as a FHIR time or dateTime whose text has more than three fraction digits.

Request

A clarification of the intended behaviour, and test cases like the rows above once it is decided. I am happy to contribute the cases.


Generated by Claude Code

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cqframework/cql-tests

All issues in cqframework/cql-tests

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.