Skip to content

Duration uncertainty #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 1, 2025
Merged

Duration uncertainty #340

merged 5 commits into from
Apr 1, 2025

Conversation

elsaperelli
Copy link
Contributor

@elsaperelli elsaperelli commented Mar 28, 2025

Summary

This PR updates the functionality of durationBetween calculations in order to match the latest descriptions in the CQL Logical Specification described here. This PR also fixes #325.

According to the CQL Logical Specification, "Note that uncertainty calculations, just like date and time comparison calculations, consider seconds and milliseconds as a single combined precision with decimal semantics". This means that the duration between calculation should NOT produce an Uncertainty in both cases: when ms are defined and when ms are not defined.

Pull requests into cql-execution require the following.
Submitter and reviewer should ✔ when done.
For items that are not-applicable, mark "N/A" and ✔.

Submitter:

  • This pull request describes why these changes were made
  • Code diff has been done and been reviewed (it does not contain: additional white space, not applicable code changes, debug statements, etc.)
  • Tests are included and test edge cases
  • Tests have been run locally and pass
  • Code coverage has not gone down and all code touched or added is covered.
  • Code passes lint and prettier (hint: use npm run test:plus to run tests, lint, and prettier)
  • All dependent libraries are appropriately updated or have a corresponding PR related to this change
  • cql4browsers.js built with npm run build:browserify if source changed.

Reviewer:

Name:

  • Code is maintainable and reusable, reuses existing code and infrastructure where appropriate, and accomplishes the task’s purpose
  • The tests appropriately test the new code, including edge cases
  • You have tried to break the code

Additional Testing Guidance

@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.46%. Comparing base (89699b5) to head (50e3ac1).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #340      +/-   ##
==========================================
+ Coverage   87.43%   87.46%   +0.02%     
==========================================
  Files          52       52              
  Lines        4536     4546      +10     
  Branches     1280     1284       +4     
==========================================
+ Hits         3966     3976      +10     
  Misses        361      361              
  Partials      209      209              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@cmoesel cmoesel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @elsaperelli. I think the approach is right on, but I'm made a small suggestion for your consideration and I think I also discovered a tiny mistake in the tests.

@elsaperelli elsaperelli force-pushed the duration-uncertainty branch 2 times, most recently from 1f41ad6 to 1693a26 Compare March 31, 2025 19:21
@elsaperelli elsaperelli marked this pull request as ready for review March 31, 2025 19:45
@elsaperelli elsaperelli requested a review from cmoesel March 31, 2025 19:45
@elsaperelli elsaperelli requested a review from hossenlopp March 31, 2025 19:45
Copy link
Member

@cmoesel cmoesel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive me for not thinking of this before, but... I think that the approach only holds true for durations when the precision is seconds and above.

In the Date, DateTime, and Time section of the Author's guide, it says (emphasis mine):

In other words, when performing comparisons or calculations for precisions of seconds and above, if milliseconds are not specified, the calculation should be performed as though milliseconds had been specified as 0.

And in the DateTime and Time sections of the reference it says something similar (again, emphasis mine):

In other words, if milliseconds are not specified, calculations for precisions above milliseconds should be performed as though milliseconds had been specified as 0.

So if the expression is milliseconds between A and B then we should not convert null milliseconds to 0. I think this means that in the duration code, we additionally need to check the unitField argument of durationBetween to make sure it's not milliseconds. Do you agree with that interpretation of the spec?

@elsaperelli elsaperelli requested a review from cmoesel April 1, 2025 14:53
@elsaperelli elsaperelli force-pushed the duration-uncertainty branch from 94a2365 to 50e3ac1 Compare April 1, 2025 15:39
Copy link
Member

@cmoesel cmoesel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Elsa! This seems to do the trick!

Copy link
Contributor

@hossenlopp hossenlopp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@hossenlopp hossenlopp merged commit c25a54c into master Apr 1, 2025
17 of 20 checks passed
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.

Uncertainty Produced for Duration Operation Involving Days Granularity
4 participants