Skip to content

Commit 4ed57ff

Browse files
author
Luke deGruchy
committed
Fix case in test CQL file to fix pipeline failure. Cleanup code in DateTime.
1 parent 221220d commit 4ed57ff

File tree

3 files changed

+5
-107
lines changed

3 files changed

+5
-107
lines changed

Src/java/engine/src/main/java/org/opencds/cqf/cql/engine/runtime/DateTime.java

Lines changed: 4 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import java.time.temporal.ChronoField;
77
import java.util.Calendar;
88
import java.util.Date;
9-
import java.util.Optional;
109
import java.util.TimeZone;
11-
import java.util.stream.Collectors;
1210

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

@@ -49,9 +47,6 @@ public DateTime(OffsetDateTime dateTime) {
4947
public DateTime(OffsetDateTime dateTime, Precision precision) {
5048
setDateTime(dateTime);
5149
this.precision = precision;
52-
53-
final String offsetDateTimeId = dateTime.getOffset().getId();
54-
5550
zoneId = toZoneId(dateTime);
5651
}
5752

@@ -134,89 +129,18 @@ else if (i == 6) {
134129
precision = Precision.fromDateTimeIndex(stringElements.length - 1);
135130
dateString = new StringBuilder().append(TemporalHelper.autoCompleteDateTimeString(dateString.toString(), precision));
136131

137-
// LUKETODO: normally, the calling method provides an offset, which is supposed to derived from the TZ
138-
// so we shouldn't do anything funky with timezones here: we should just interpret the offset as passed and
139-
// process the minutes correctly
140-
141132
// If the incoming string has an offset specified, use that offset
142133
// Otherwise, parse as a LocalDateTime and then interpret that in the evaluation timezone
143134

144135
if (offset != null) {
145-
// LUKETODO: this is for debugging purposes: remove when testing is done
146-
final ZoneId zoneId = ZoneId.systemDefault();
147-
final int totalSeconds = ZonedDateTime.now().getOffset().getTotalSeconds();
148-
final int totalMinutes = totalSeconds / 60;
149-
final int totalMinutesModulo60 = totalMinutes % 60;
150-
151-
final boolean hoursPositiveNumber = offset.intValue() >= 0;
152-
final boolean minutesPositiveNumber = totalMinutesModulo60 >= 0;
153-
154-
final int oldCalculation = new BigDecimal("60").multiply(offset.remainder(BigDecimal.ONE)).intValue();
155-
156-
// final int minutes = totalMinutesModulo60 == 0
157-
final int minutes = totalMinutesModulo60 != 500000
158-
? oldCalculation
159-
: (hoursPositiveNumber == minutesPositiveNumber) ? totalMinutesModulo60 : Math.negateExact(totalMinutesModulo60); // This is for a half hour or 45 minute timezone, such as Newfoundland, Canada
160-
dateString.append(ZoneOffset.ofHoursMinutes(offset.intValue(),
161-
minutes)
162-
.getId());
136+
dateString.append(ZoneOffset.ofHoursMinutes(offset.intValue(), new BigDecimal("60").multiply(offset.remainder(BigDecimal.ONE)).intValue()).getId());
163137
setDateTime(OffsetDateTime.parse(dateString.toString()));
164138
}
165139
else {
166140
setDateTime(TemporalHelper.toOffsetDateTime(LocalDateTime.parse(dateString.toString())));
167141
}
168142

169-
// This is the number of milliseconds to add to UTC
170-
final int offset1 = TimeZone.getDefault().getOffset(new Date().toInstant().toEpochMilli());
171-
final Integer intValueOfOffset = Optional.ofNullable(offset).map(BigDecimal::intValue).orElse(-1);
172-
173-
zoneId =
174-
// null;
175-
toZoneId(offset);
176-
177-
/*
178-
0 = "+12:00"
179-
1 = "+14:00"
180-
2 = "-01:00"
181-
3 = "-03:00"
182-
4 = "-09:00"
183-
5 = "-07:00"
184-
6 = "-02:30"
185-
7 = "-05:00"
186-
8 = "+03:00"
187-
9 = "+01:00"
188-
10 = "+04:30"
189-
11 = "+07:00"
190-
12 = "+05:45"
191-
13 = "+05:00"
192-
14 = "+06:30"
193-
15 = "+10:00"
194-
16 = "+09:00"
195-
17 = "Z"
196-
18 = "-11:00"
197-
19 = "-06:00"
198-
20 = "+13:45"
199-
21 = "+10:30"
200-
22 = "+11:00"
201-
23 = "+13:00"
202-
24 = "-09:30"
203-
25 = "-08:00"
204-
26 = "-02:00"
205-
27 = "-04:00"
206-
28 = "+02:00"
207-
29 = "+03:30"
208-
30 = "+04:00"
209-
31 = "+06:00"
210-
32 = "+08:45"
211-
33 = "+08:00"
212-
34 = "-12:00"
213-
35 = "+05:30"
214-
36 = "+09:30"
215-
37 = "-10:00"
216-
*/
217-
218-
// zoneOffsetIds.stream()
219-
// .filter(offsetId )
143+
zoneId = toZoneId(offset);
220144
}
221145

222146
private static ZoneId toZoneId(BigDecimal offset) {
@@ -280,17 +204,7 @@ private static boolean isZoneEquivalentToOffset(ZoneId zoneId, BigDecimal offset
280204

281205
final double zoneDouble = offsetHours.doubleValue();
282206
final double offsetDouble = offset.doubleValue();
283-
final boolean result = zoneDouble == offsetDouble;
284-
return result;
285-
286-
// .map(zoneId -> LocalDateTime.now().atZone(zoneId))
287-
// .map(ZonedDateTime::getOffset)
288-
// .map(zonedDateTimeoffset -> zonedDateTimeoffset.get(ChronoField.OFFSET_SECONDS))
289-
290-
// .map(offsetSeconds -> offsetSeconds / 60)
291-
// .map(offsetMinutes -> BigDecimal.valueOf(offsetMinutes).divide(BigDecimal.valueOf(60), RoundingMode.HALF_UP))
292-
// .map(BigDecimal::doubleValue)
293-
// .filter(bigDecimal -> bigDecimal.equals(offset))
207+
return zoneDouble == offsetDouble;
294208
}
295209

296210
public DateTime expandPartialMinFromPrecision(Precision thePrecision) {
@@ -363,12 +277,8 @@ public Integer compare(BaseTemporal other, boolean forSort) {
363277
public OffsetDateTime getNormalized(Precision precision) {
364278
return getNormalized(precision, zoneId);
365279
}
366-
public OffsetDateTime getNormalized(Precision precision, ZoneId nullableZoneId) {
367280

368-
// LUKETODO: remove this:
369-
// zoneId = null;
370-
// LUKETODO: for debugging only
371-
final ZoneId aDefault = TimeZone.getDefault().toZoneId();
281+
public OffsetDateTime getNormalized(Precision precision, ZoneId nullableZoneId) {
372282
if (precision.toDateTimeIndex() > Precision.DAY.toDateTimeIndex()) {
373283
if (nullableZoneId != null) {
374284
return dateTime.atZoneSameInstant(nullableZoneId).toOffsetDateTime();
@@ -392,25 +302,12 @@ public Integer compareToPrecision(BaseTemporal other, Precision thePrecision) {
392302

393303
// adjust dates to evaluation offset
394304
OffsetDateTime leftDateTime = this.getNormalized(thePrecision);
395-
// LUKETODO; normalize to "this" zoneId?
396305
OffsetDateTime rightDateTime = ((DateTime) other).getNormalized(thePrecision, getZoneId());
397306

398307
if (!leftMeetsPrecisionRequirements || !rightMeetsPrecisionRequirements) {
399308
thePrecision = Precision.getLowestDateTimePrecision(this.precision, other.precision);
400309
}
401310

402-
403-
// final ZoneOffset offset1 = ZonedDateTime.now().getOffset();
404-
// final BigDecimal offsetAsBigDecimal = TemporalHelper.zoneToOffset(offset1);
405-
406-
// GOOD: Mountain
407-
// leftDateTime = {OffsetDateTime@3605} "2000-03-15T05:30:25.200-07:00"
408-
// rightDateTime = {OffsetDateTime@3610} "2000-03-15T05:14:47.500-07:00"
409-
410-
// BAD: Newfoundland
411-
// leftDateTime = {OffsetDateTime@3770} "2000-03-15T09:00:25.200-03:30"
412-
// rightDateTime = {OffsetDateTime@3775} "2000-03-15T08:44:47.500-03:30"
413-
414311
for (int i = 0; i < thePrecision.toDateTimeIndex() + 1; ++i) {
415312
int leftComp = leftDateTime.get(Precision.getDateTimeChronoFieldFromIndex(i));
416313
int rightComp = rightDateTime.get(Precision.getDateTimeChronoFieldFromIndex(i));

Src/java/engine/src/test/java/org/opencds/cqf/cql/engine/execution/CqlPerformanceIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import static org.testng.Assert.assertTrue;
1717

18+
// LUKETODO: this test suite is failing with performance problems
1819
public class CqlPerformanceIT extends CqlTestBase {
1920

2021
private static final Integer ITERATIONS = 200;

0 commit comments

Comments
 (0)