Skip to content

Commit

Permalink
Bugfix that works on standard timezone workstation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedegruchy committed Oct 25, 2023
1 parent 682e04e commit b715e61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.opencds.cqf.cql.engine.runtime;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.*;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
Expand Down Expand Up @@ -128,7 +126,16 @@ else if (i == 6) {
// Otherwise, parse as a LocalDateTime and then interpret that in the evaluation timezone

if (offset != null) {
dateString.append(ZoneOffset.ofHoursMinutes(offset.intValue(), new BigDecimal("60").multiply(offset.remainder(BigDecimal.ONE)).intValue()).getId());
final int totalSeconds = ZonedDateTime.now().getOffset().getTotalSeconds();
final int totalMinutes = totalSeconds / 60;
final int totalMinutesModulo60 = totalMinutes % 60;

final int minutes = totalMinutesModulo60 == 0
? new BigDecimal("60").multiply(offset.remainder(BigDecimal.ONE)) .intValue()
: Math.abs(totalMinutesModulo60); // This is for a half hour or 45 minute timezone, such as Newfoundland, Canada
dateString.append(ZoneOffset.ofHoursMinutes(offset.intValue(),
minutes)
.getId());
setDateTime(OffsetDateTime.parse(dateString.toString()));
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void test_cql_timezone_tests() {
// possible set of expressions from the CQL engine API
// prior to evaluating them all

// LUKETODO: the below CQL file compiles, it just fails here:
var result = e.evaluate(toElmIdentifier("CqlTimeZoneTestSuite"), evalTime);

for (var entry : result.expressionResults.entrySet()) {
Expand Down

0 comments on commit b715e61

Please sign in to comment.