Skip to content

Commit

Permalink
Add tests to new unit test. Leave open the question of how to handle …
Browse files Browse the repository at this point in the history
…DST. TODO: 2 param getNormalized().
  • Loading branch information
lukedegruchy committed Oct 26, 2023
1 parent 4ed57ff commit 40afa1d
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.function.Predicate;

import org.opencds.cqf.cql.engine.exception.InvalidDateTime;

Expand Down Expand Up @@ -143,68 +144,8 @@ else if (i == 6) {
zoneId = toZoneId(offset);
}

private static ZoneId toZoneId(BigDecimal offset) {
return ZoneId.getAvailableZoneIds()
.stream()
.map(ZoneId::of)
.filter(zoneId -> isZoneEquivalentToOffset(zoneId, offset))
.findFirst()
.orElse(null);
}

private ZoneId toZoneId(OffsetDateTime offsetDateTime) {
return ZoneId.getAvailableZoneIds()
.stream()
.map(ZoneId::of)
.filter(zoneId -> isZoneEquivalentToOffset(zoneId, offsetDateTime))
.findFirst()
.orElse(null);
}

private static ZoneId toZoneId(ZoneOffset offset) {
return ZoneId.getAvailableZoneIds()
.stream()
.map(ZoneId::of)
.filter(zoneId -> isZoneEquivalentToOffset(zoneId, offset))
.findFirst()
.orElse(null);
}

private boolean isZoneEquivalentToOffset(ZoneId zoneId, OffsetDateTime offsetDateTime) {
if (offsetDateTime== null) {
return false;
}

final ZoneOffset zoneIdOffset = LocalDateTime.now().atZone(zoneId).getOffset();
final ZoneOffset offsetDateTimeOffset = offsetDateTime.getOffset();

return zoneIdOffset.equals(offsetDateTimeOffset);
}

private static boolean isZoneEquivalentToOffset(ZoneId zoneId, ZoneOffset zoneOffset) {
if (zoneOffset == null) {
return false;
}

final ZoneOffset zoneIdOffset = LocalDateTime.now().atZone(zoneId).getOffset();

return zoneIdOffset.equals(zoneOffset);
}

private static boolean isZoneEquivalentToOffset(ZoneId zoneId, BigDecimal offset) {
if (offset == null) {
return false;
}

final ZoneOffset zoneOffset = LocalDateTime.now().atZone(zoneId).getOffset();
final long offsetSeconds = zoneOffset.getLong(ChronoField.OFFSET_SECONDS);
final BigDecimal offsetMinutes = BigDecimal.valueOf(offsetSeconds).divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING);
final BigDecimal offsetHours = offsetMinutes
.divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING);

final double zoneDouble = offsetHours.doubleValue();
final double offsetDouble = offset.doubleValue();
return zoneDouble == offsetDouble;
public ZoneId getZoneId() {
return zoneId;
}

public DateTime expandPartialMinFromPrecision(Precision thePrecision) {
Expand Down Expand Up @@ -290,11 +231,6 @@ public OffsetDateTime getNormalized(Precision precision, ZoneId nullableZoneId)
return dateTime;
}

// LUKETODO: better name
public ZoneId getZoneId() {
return zoneId;
}

@Override
public Integer compareToPrecision(BaseTemporal other, Precision thePrecision) {
boolean leftMeetsPrecisionRequirements = this.precision.toDateTimeIndex() >= thePrecision.toDateTimeIndex();
Expand Down Expand Up @@ -367,4 +303,50 @@ public static DateTime fromJavaDate(Date date) {
calendar.setTime(date);
return new DateTime(OffsetDateTime.ofInstant(calendar.toInstant(), calendar.getTimeZone().toZoneId()), Precision.MILLISECOND);
}

private ZoneId toZoneId(OffsetDateTime offsetDateTime) {
return toZoneId(offsetDateTime.getOffset());
}

private static ZoneId toZoneId(ZoneOffset offset) {
if (offset == null) {
return null;
}

return toZoneId(zoneId -> isZoneEquivalentToOffset(zoneId, offset));
}

private static ZoneId toZoneId(BigDecimal offset) {
if (offset == null) {
return null;
}

return toZoneId(zoneId -> isZoneEquivalentToOffset(zoneId, offset));
}

private static ZoneId toZoneId(Predicate<ZoneId> predicate) {
return ZoneId.getAvailableZoneIds()
.stream()
.map(ZoneId::of)
.filter(predicate)
.findFirst()
.orElse(null);
}

private static boolean isZoneEquivalentToOffset(ZoneId zoneId, ZoneOffset zoneOffset) {
final ZoneOffset zoneIdOffset = LocalDateTime.now().atZone(zoneId).getOffset();

return zoneIdOffset.equals(zoneOffset);
}

private static boolean isZoneEquivalentToOffset(ZoneId zoneId, BigDecimal offset) {
final ZoneOffset zoneOffset = LocalDateTime.now().atZone(zoneId).getOffset();
final long offsetSeconds = zoneOffset.getLong(ChronoField.OFFSET_SECONDS);
final BigDecimal offsetMinutes = BigDecimal.valueOf(offsetSeconds)
.divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING);
final BigDecimal offsetHours = offsetMinutes
.divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING);

return offsetHours.doubleValue() == offset.doubleValue();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,167 @@
package org.opencds.cqf.cql.engine.runtime;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.List;

import static org.testng.Assert.*;

public class DateTimeTest {
private static final LocalDateTime LDT_2023_10_26_22_12_0 = LocalDateTime.of(2023, Month.OCTOBER, 26, 22, 12, 0);
private static final LocalDateTime LDT_2023_11_03_02_52_0 = LocalDateTime.of(2023, Month.NOVEMBER, 3, 2, 52, 0);
// This is OUTSIDE of Daylight Savings Time
private static final LocalDateTime LDT_2024_02_27_07_28_0 = LocalDateTime.of(2024, Month.FEBRUARY, 27, 7, 28, 0);
private static final LocalDateTime LDT_2024_06_15_23_32_0 = LocalDateTime.of(2024, Month.JULY, 15, 23, 32, 0);

private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");

private static final String _2023_10_26 = FORMATTER.format(LDT_2023_10_26_22_12_0);
private static final String _2023_11_03 = FORMATTER.format(LDT_2023_11_03_02_52_0);
private static final String _2024_02_27 = FORMATTER.format(LDT_2024_02_27_07_28_0);
private static final String _2024_06_15 = FORMATTER.format(LDT_2024_06_15_23_32_0);

private static final List<Integer> _2023_10_26_22_12_0 = toList(LDT_2024_06_15_23_32_0);

private static final List<Integer> _2023_11_03_02_52_0 = toList(LDT_2023_11_03_02_52_0);
private static final List<Integer> _2024_02_27_07_28_0 = toList(LDT_2024_02_27_07_28_0);
private static final List<Integer> _2024_06_15_23_32_0 = toList(LDT_2024_06_15_23_32_0);

// LUKETODO: change each of these offsets when dealing with standard (non-DST) time
private static final ZoneOffset OFFSET_NORTH_AMERICA_EASTERN = ZoneOffset.of("-04:00");
private static final ZoneOffset OFFSET_NORTH_AMERICA_MOUNTAIN = ZoneOffset.of("-06:00");
private static final ZoneOffset OFFSET_NORTH_AMERICA_NEWFOUNDLAND = ZoneOffset.of("-02:30");
private static final ZoneOffset OFFSET_NORTH_AMERICA_NEWFOUNDLAND_DST = ZoneOffset.of("-03:30");

private static final BigDecimal BIG_DECIMAL_OFFSET_NORTH_AMERICA_EASTERN = toBigDecimal(OFFSET_NORTH_AMERICA_EASTERN);
private static final BigDecimal BIG_DECIMAL_OFFSET_NORTH_AMERICA_MOUNTAIN = toBigDecimal(OFFSET_NORTH_AMERICA_MOUNTAIN);
private static final BigDecimal BIG_DECIMAL_OFFSET_NORTH_AMERICA_NEWFOUNDLAND = toBigDecimal(OFFSET_NORTH_AMERICA_NEWFOUNDLAND);
private static final BigDecimal BIG_DECIMAL_OFFSET_NORTH_AMERICA_NEWFOUNDLAND_DST = toBigDecimal(OFFSET_NORTH_AMERICA_NEWFOUNDLAND_DST);

private static BigDecimal toBigDecimal(ZoneOffset zoneOffset) {
final long offsetSeconds = zoneOffset.getLong(ChronoField.OFFSET_SECONDS);
final BigDecimal offsetMinutes = BigDecimal.valueOf(offsetSeconds)
.divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING);
return offsetMinutes .divide(BigDecimal.valueOf(60), 2, RoundingMode.CEILING);
}

private static List<Integer> toList(LocalDateTime localDateTime) {
return List.of(localDateTime.getYear(), localDateTime.getMonthValue(), localDateTime.getDayOfMonth(), localDateTime.getHour(), localDateTime.getMinute(), localDateTime.getSecond());
}

@DataProvider
private static Object[][] dateStrings() {
return new Object[][] {
{_2023_10_26, null, Precision.HOUR},
{_2023_10_26, ZoneOffset.UTC, Precision.HOUR},
{_2023_10_26, OFFSET_NORTH_AMERICA_EASTERN, Precision.HOUR},
{_2023_10_26, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.HOUR},
{_2023_10_26, OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.HOUR},
{_2023_10_26, null, Precision.MILLISECOND},
{_2023_11_03, ZoneOffset.UTC, Precision.MILLISECOND},
{_2023_11_03, OFFSET_NORTH_AMERICA_EASTERN, Precision.MILLISECOND},
{_2023_11_03, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.MILLISECOND},
{_2023_11_03, OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.MILLISECOND},
{_2024_02_27, null, Precision.HOUR},
{_2024_02_27, ZoneOffset.UTC, Precision.HOUR},
{_2024_02_27, OFFSET_NORTH_AMERICA_EASTERN, Precision.HOUR},
{_2024_02_27, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.HOUR},
{_2024_02_27, OFFSET_NORTH_AMERICA_NEWFOUNDLAND_DST, Precision.HOUR},
{_2024_06_15, null, Precision.MILLISECOND},
{_2024_06_15, ZoneOffset.UTC, Precision.MILLISECOND},
{_2024_06_15, OFFSET_NORTH_AMERICA_EASTERN, Precision.MILLISECOND},
{_2024_06_15, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.MILLISECOND},
{_2024_06_15, OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.MILLISECOND}
};
}

@Test(dataProvider = "dateStrings")
void testDateStrings(String dateString, ZoneOffset zoneOffset, Precision precision) {
final DateTime dateTime = new DateTime(dateString, zoneOffset);

final OffsetDateTime normalizedDateTime = dateTime.getNormalized(precision);

assertEquals(normalizedDateTime, dateTime.getDateTime());

Check failure on line 92 in Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/runtime/DateTimeTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

DateTimeTest.testDateStrings[14](2024-02-27T07:28:00, -03:30, hour)

java.lang.AssertionError: expected [2024-02-27T07:28-03:30] but found [2024-02-27T10:58Z]
Raw output
java.lang.AssertionError: expected [2024-02-27T07:28-03:30] but found [2024-02-27T10:58Z]
	at org.testng.Assert.fail(Assert.java:99)
	at org.testng.Assert.failNotEquals(Assert.java:1037)
	at org.testng.Assert.assertEqualsImpl(Assert.java:140)
	at org.testng.Assert.assertEquals(Assert.java:122)
	at org.testng.Assert.assertEquals(Assert.java:617)
	at org.opencds.cqf.cql.engine.runtime.DateTimeTest.testDateStrings(DateTimeTest.java:92)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.testng.TestRunner.privateRun(TestRunner.java:794)
	at org.testng.TestRunner.run(TestRunner.java:596)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
	at org.testng.SuiteRunner.run(SuiteRunner.java:276)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
	at org.testng.TestNG.runSuites(TestNG.java:1063)
	at org.testng.TestNG.run(TestNG.java:1031)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:145)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:92)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy5.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
}

@DataProvider
private static Object[][] offsetPrecisions() {
return new Object[][] {
// {LDT_2023_10_26_22_12_0, ZoneOffset.UTC, Precision.HOUR},
// {LDT_2023_10_26_22_12_0, OFFSET_NORTH_AMERICA_EASTERN, Precision.HOUR},
// {LDT_2023_10_26_22_12_0, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.HOUR},
// {LDT_2023_10_26_22_12_0, OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.HOUR},
// {LDT_2023_11_03_02_52_0, ZoneOffset.UTC, Precision.MILLISECOND},
// {LDT_2023_11_03_02_52_0, OFFSET_NORTH_AMERICA_EASTERN, Precision.MILLISECOND},
// {LDT_2023_11_03_02_52_0, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.MILLISECOND},
// {LDT_2023_11_03_02_52_0, OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.MILLISECOND},
// {LDT_2024_02_27_07_28_0, ZoneOffset.UTC, Precision.HOUR},
{LDT_2024_02_27_07_28_0, OFFSET_NORTH_AMERICA_EASTERN, Precision.HOUR},
// {LDT_2024_02_27_07_28_0, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.HOUR},
{LDT_2024_02_27_07_28_0, OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.HOUR},
// {LDT_2024_06_15_23_32_0, ZoneOffset.UTC, Precision.MILLISECOND},
// {LDT_2024_06_15_23_32_0, OFFSET_NORTH_AMERICA_EASTERN, Precision.MILLISECOND},
// {LDT_2024_06_15_23_32_0, OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.MILLISECOND},
// {LDT_2024_06_15_23_32_0, OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.MILLISECOND},
};
}

@Test(dataProvider = "offsetPrecisions")
void testOffsetPrecisions(LocalDateTime localDateTime, ZoneOffset zoneOffset, Precision precision) {
final OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime, zoneOffset);
final DateTime dateTimeNoPrecision = new DateTime(offsetDateTime);
final DateTime dateTimePrecision = new DateTime(offsetDateTime, precision);

final OffsetDateTime normalizedDateTimeNoPrecision = dateTimeNoPrecision.getNormalized(precision);
final OffsetDateTime normalizedDateTimePrecision = dateTimePrecision.getNormalized(precision);

assertEquals(normalizedDateTimeNoPrecision, dateTimeNoPrecision.getDateTime());

Check failure on line 126 in Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/runtime/DateTimeTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

DateTimeTest.testOffsetPrecisions[1](2024-02-27T07:28, -02:30, hour)

java.lang.AssertionError: expected [2024-02-27T07:28-02:30] but found [2024-02-27T06:28-03:30]
Raw output
java.lang.AssertionError: expected [2024-02-27T07:28-02:30] but found [2024-02-27T06:28-03:30]
	at org.testng.Assert.fail(Assert.java:99)
	at org.testng.Assert.failNotEquals(Assert.java:1037)
	at org.testng.Assert.assertEqualsImpl(Assert.java:140)
	at org.testng.Assert.assertEquals(Assert.java:122)
	at org.testng.Assert.assertEquals(Assert.java:617)
	at org.opencds.cqf.cql.engine.runtime.DateTimeTest.testOffsetPrecisions(DateTimeTest.java:126)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.testng.TestRunner.privateRun(TestRunner.java:794)
	at org.testng.TestRunner.run(TestRunner.java:596)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
	at org.testng.SuiteRunner.run(SuiteRunner.java:276)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
	at org.testng.TestNG.runSuites(TestNG.java:1063)
	at org.testng.TestNG.run(TestNG.java:1031)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:145)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:92)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy5.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
assertEquals(normalizedDateTimePrecision, dateTimePrecision.getDateTime());
}

@DataProvider
private static Object[][] bigDecimals() {
return new Object[][] {
{null, Precision.HOUR, _2023_10_26_22_12_0},
{BigDecimal.ZERO, Precision.HOUR, _2023_10_26_22_12_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_EASTERN, Precision.HOUR, _2023_10_26_22_12_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.HOUR, _2023_10_26_22_12_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.HOUR, _2023_10_26_22_12_0},
{null, Precision.MILLISECOND, _2023_11_03_02_52_0},
{BigDecimal.ZERO, Precision.MILLISECOND, _2023_11_03_02_52_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_EASTERN, Precision.MILLISECOND, _2023_11_03_02_52_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.MILLISECOND, _2023_11_03_02_52_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.MILLISECOND, _2023_11_03_02_52_0},
{null, Precision.HOUR, _2024_02_27_07_28_0},
{BigDecimal.ZERO, Precision.HOUR, _2024_02_27_07_28_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_EASTERN, Precision.HOUR, _2024_02_27_07_28_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.HOUR, _2024_02_27_07_28_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.HOUR, _2024_02_27_07_28_0},
{null, Precision.MILLISECOND, _2024_06_15_23_32_0},
{BigDecimal.ZERO, Precision.MILLISECOND, _2024_06_15_23_32_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_EASTERN, Precision.MILLISECOND, _2024_06_15_23_32_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_MOUNTAIN, Precision.HOUR, _2024_06_15_23_32_0},
{BIG_DECIMAL_OFFSET_NORTH_AMERICA_NEWFOUNDLAND, Precision.MILLISECOND, _2024_06_15_23_32_0},
};
}

@Test(dataProvider = "bigDecimals")
void testBigDecimal(BigDecimal offset, Precision precision, List<Integer> dateElements) {
final int[] dateElementsArray = dateElements.stream().mapToInt(anInt -> anInt).toArray();
final DateTime dateTime = new DateTime(offset, dateElementsArray);

final OffsetDateTime normalizedDateTime = dateTime.getNormalized(precision);

assertEquals(normalizedDateTime, dateTime.getDateTime());

Check failure on line 163 in Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/runtime/DateTimeTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

DateTimeTest.testBigDecimal[14](-2.50, hour, [2024, 2, 27, 7, 28, 0])

java.lang.AssertionError: expected [2024-02-27T07:28-02:30] but found [2024-02-27T06:28-03:30]
Raw output
java.lang.AssertionError: expected [2024-02-27T07:28-02:30] but found [2024-02-27T06:28-03:30]
	at org.testng.Assert.fail(Assert.java:99)
	at org.testng.Assert.failNotEquals(Assert.java:1037)
	at org.testng.Assert.assertEqualsImpl(Assert.java:140)
	at org.testng.Assert.assertEquals(Assert.java:122)
	at org.testng.Assert.assertEquals(Assert.java:617)
	at org.opencds.cqf.cql.engine.runtime.DateTimeTest.testBigDecimal(DateTimeTest.java:163)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.testng.TestRunner.privateRun(TestRunner.java:794)
	at org.testng.TestRunner.run(TestRunner.java:596)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
	at org.testng.SuiteRunner.run(SuiteRunner.java:276)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
	at org.testng.TestNG.runSuites(TestNG.java:1063)
	at org.testng.TestNG.run(TestNG.java:1031)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:145)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:92)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy5.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
}

// LUKETODO: test getNormalized
// 1) All constructors with null offsets: ensure we default to default timezone
// 2) Each constructor with its own offset : ensure we switch to that timezone
// 3) Each constructor with its own offset that happens to be the default timezone
// LUKETODO: consider 2 param getNormalized
}

0 comments on commit 40afa1d

Please sign in to comment.