Skip to content

Commit

Permalink
Add test for default timezone offset of DateTime (#1423)
Browse files Browse the repository at this point in the history
* Add test for timezone offset

* Add comment

---------

Co-authored-by: JP <[email protected]>
  • Loading branch information
antvaset and JPercival authored Oct 18, 2024
1 parent a7c1636 commit 35668e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ define Issue34A: Now()
define TimeOfDayTest: TimeOfDay()

//Today
define Issue34B: Today()
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)

0 comments on commit 35668e9

Please sign in to comment.