-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix DateTime initialization and comparison code to deal correctly wit…
…h half hour and fifteen minute timezones (#1259) * Add test to run on Newfoundland TZ machine. * Copy all 4 tests failing on the Newfoundland laptop into the timezone CQL file. * Copy all 4 tests failing on the Newfoundland laptop into the timezone CQL file. * Change Newfoundland tests to to SoftAssert. * Ensure all tests fail in Newfoundland. * Fix wrong test name. * Successfully set timezone within a unit test and replicated the expected failures on an EST/EDT workstation. * Parameterized test with different timezones. * Bugfix that works on standard timezone workstation. * Add parameterized tests for CqlTypesOperatorsTest, which fails on the Newfoundland workstation due a flaw in the bugfix. * Instantiate ZoneId in DateTime from all constructors. Add getter. Add two getNormalized() methods, one of which takes another ZoneId. Pass in the "this" DateTime's zoneId when normalizing the "other" DateTime. Add stub with comments for new DateTimeTest. Lots of TODOs and cleanup needed. Need to test on Newfoundland workstation. * Fix case in test CQL file to fix pipeline failure. Cleanup code in DateTime. * Add tests to new unit test. Leave open the question of how to handle DST. TODO: 2 param getNormalized(). * More tweaks. Try to optimize the performance of DateTime. Still haven't figured out why Newfoundland in non-DST fails. * Comment out experimental code that may impact performance. * Stop using ZoneId and use ZoneOffset instead. This seems to resolve the Newfoundland non DST bug. * Remove all remnants of old ZoneId code. Add more unit tests. * More cleanup.
- Loading branch information
1 parent
7091010
commit 2751734
Showing
8 changed files
with
677 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlTimezoneTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.opencds.cqf.cql.engine.execution; | ||
|
||
import org.hl7.elm.r1.VersionedIdentifier; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testng.annotations.*; | ||
import org.testng.asserts.SoftAssert; | ||
|
||
import java.util.TimeZone; | ||
|
||
@SuppressWarnings("removal") | ||
public class CqlTimezoneTests extends CqlTestBase { | ||
private static final Logger logger = LoggerFactory.getLogger(CqlTimezoneTests.class); | ||
|
||
private static final VersionedIdentifier library = new VersionedIdentifier().withId("CqlTimezoneTests"); | ||
|
||
@Test(dataProvider = "timezones") | ||
public void testExpressionsProblematicForWeirdTimezones(String timezone) { | ||
final String oldTz = System.getProperty("user.timezone"); | ||
// This is the ONLY thing that will work. System.setProperty() and -Duser.timezone do NOT work | ||
TimeZone.setDefault(TimeZone.getTimeZone(timezone)); | ||
|
||
try { | ||
final SoftAssert softAssert = new SoftAssert(); | ||
|
||
evaluateExpression("After_SameHour", false, softAssert); | ||
evaluateExpression("SameAs_SameHour", true, softAssert); | ||
evaluateExpression("SameOrAfter_HourBefore", false, softAssert); | ||
evaluateExpression("SameOrBefore_SameHour", true, softAssert); | ||
|
||
softAssert.assertAll(); | ||
} finally { | ||
TimeZone.setDefault(TimeZone.getTimeZone(oldTz)); | ||
} | ||
} | ||
|
||
private void evaluateExpression(String functionName, boolean expectedResult, SoftAssert softAssert) { | ||
Object result = engine.expression(library, functionName).value(); | ||
softAssert.assertEquals(result, expectedResult, functionName); | ||
} | ||
|
||
} |
Oops, something went wrong.