diff --git a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.java b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.java index 5ecae9edd..a19fd52a1 100644 --- a/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.java +++ b/Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.java @@ -4,6 +4,10 @@ import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.*; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.EnumSet; +import java.util.List; import org.hl7.elm.r1.VersionedIdentifier; import org.junit.jupiter.api.Test; import org.opencds.cqf.cql.engine.elm.executing.AfterEvaluator; @@ -104,4 +108,23 @@ void today() { // Assertions.assertTrue(((DateTime) // result).getDateTime().getOffset().equals(TemporalHelper.getDefaultZoneOffset())); } + + @Test + void defaultTimezoneOffset() { + // Disable expression caching so that we can re-evaluate the same expression in different time zones + var engine = new CqlEngine(environment, EnumSet.noneOf(CqlEngine.Options.class)); + + for (var zoneId : List.of("America/New_York", "Europe/London", "Pacific/Auckland")) { + var evaluationZonedDateTime = ZonedDateTime.of(2024, 10, 3, 15, 54, 0, 0, ZoneId.of(zoneId)); + + // Issue1420 calculates the difference in hours between `DateTime(y, m, d, h, m, s, ms)` and + // `DateTime(y, m, d, h, m, s, ms, 0)`, so it returns the timezone offset of the first DateTime. + // The first DateTime should have the timezone offset of the evaluation request as per the spec. + // CQL also has `timezoneoffset from DateTime(...)` but here we are testing a more complex scenario. + var value = engine.expression(library, "Issue1420", evaluationZonedDateTime) + .value(); + var expected = evaluationZonedDateTime.getOffset().getTotalSeconds() / 3600; + assertEquals(expected, value); + } + } } diff --git a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.cql b/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.cql index 256abea06..57f5bdb84 100644 --- a/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.cql +++ b/Src/java/engine/src/test/resources/org/opencds/cqf/cql/engine/execution/CqlDateTimeOperatorsTest.cql @@ -20,4 +20,7 @@ define Issue34A: Now() define TimeOfDayTest: TimeOfDay() //Today -define Issue34B: Today() \ No newline at end of file +define Issue34B: Today() + +// Default timezoneOffset +define Issue1420: hours between DateTime(2024, 10, 3, 15, 54, 0, 0) and DateTime(2024, 10, 3, 15, 54, 0, 0, 0) \ No newline at end of file