Repository navigation
Use execution timezone offset for ToDateTime(String) - #387
Conversation
Per the CQL spec, when a string has no timezone offset the offset of the evaluation request timestamp is assumed. DateTime.parse now accepts an optional default offset, which ToDateTime supplies from the execution context. Other DateTime.parse callers are unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #387 +/- ##
=======================================
Coverage 89.19% 89.19%
=======================================
Files 60 60
Lines 5062 5064 +2
Branches 1445 1446 +1
=======================================
+ Hits 4515 4517 +2
Misses 315 315
Partials 232 232 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cmoesel
left a comment
There was a problem hiding this comment.
Thank you for the contribution, @cpruijsen. This looks really good and fixes a bug that's probably been there for quite a long time!
I also confirmed that if I re-enable those four skipped tests, they all pass. If you have Java 17 and Gradle 9 installed on your system, please feel free to remove those tests from the skip file and regenerate the ELM bits via npm run build:spec-test-data. If you don't have Java 17 and Gradle 9, however, I can either push up a commit to your branch that re-enables them or we'll handle it post PR. What is your preference?
|
Thanks! I removed the four tests from the skip list and regenerated the ELM in c368a16. They all pass locally. |
cmoesel
left a comment
There was a problem hiding this comment.
Perfect. Thanks for the contribution, @cpruijsen!
Fixes #385
ToDateTime(String)now uses the execution timezone offset when the string has no offset, instead of the host machine's offset (new Date().getTimezoneOffset()). This matches the CQL specification (Appendix B, ToDateTime): "If no timezone offset is supplied, the timezone offset of the evaluation request timestamp is assumed." DateTime literals, theDateTime(...)selector and theToDateTime(Date)overload already do this.Changes
src/datatypes/datetime.ts:DateTime.parseaccepts an optionaldefaultTimezoneOffset, used only when the string has noZand no explicit offset.src/elm/type.ts:ToDateTime.execpassesctx.getExecutionDateTime().timezoneOffsetfor the String overload, the same value theDateoverload uses.DateTime.parsecallers (cql-patient.tsand the min/max constants) are unchanged because the parameter is optional.This is the fix suggested in the issue. A default in the
DateTimeconstructor would also work, but it would change every other caller, including patient data parsing.Result
Execution offset
+00:00, host at-06:00:ToDateTime('2014-01-01T12:05')2014-01-01T12:05-06:002014-01-01T12:05+00:00ToDateTime('2014-01-01T12:05') = @2014-01-01T12:05falsetrueToDateTime('2014-01-01T12:05Z')+00:00+00:00ToDateTime('2014-01-01T12:05:05.955+01:30')+01:30+01:30Tests
test/datatypes/datetime-test.ts:DateTime.parseuses the default offset only when the string has none.test/elm/convert/convert-test.ts:ToDateTime('2015-01-02')gets the execution offset. The test uses-3.25, which no real time zone uses, so it cannot pass by matching the host offset.Both new offset tests fail without the source change and pass with it.
Follow-up
The four
skip-list.txtentries (CqlTypeOperatorsTest.Convert.StringToDateTimeandCqlTypeOperatorsTest.ToDateTime.ToDateTime1toToDateTime3) stay skipped. The skip markers live in the generated spec-test JSON, which needs regeneration with the translator, so I left that out of this PR. Evaluated directly, those expressions now return the execution offset.Submitter:
npm run checkto run tests, lint, and prettier)Reviewer:
Name: