6
6
import java .time .temporal .ChronoField ;
7
7
import java .util .Calendar ;
8
8
import java .util .Date ;
9
- import java .util .Optional ;
10
9
import java .util .TimeZone ;
11
- import java .util .stream .Collectors ;
12
10
13
11
import org .opencds .cqf .cql .engine .exception .InvalidDateTime ;
14
12
@@ -49,9 +47,6 @@ public DateTime(OffsetDateTime dateTime) {
49
47
public DateTime (OffsetDateTime dateTime , Precision precision ) {
50
48
setDateTime (dateTime );
51
49
this .precision = precision ;
52
-
53
- final String offsetDateTimeId = dateTime .getOffset ().getId ();
54
-
55
50
zoneId = toZoneId (dateTime );
56
51
}
57
52
@@ -134,89 +129,18 @@ else if (i == 6) {
134
129
precision = Precision .fromDateTimeIndex (stringElements .length - 1 );
135
130
dateString = new StringBuilder ().append (TemporalHelper .autoCompleteDateTimeString (dateString .toString (), precision ));
136
131
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
-
141
132
// If the incoming string has an offset specified, use that offset
142
133
// Otherwise, parse as a LocalDateTime and then interpret that in the evaluation timezone
143
134
144
135
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 ());
163
137
setDateTime (OffsetDateTime .parse (dateString .toString ()));
164
138
}
165
139
else {
166
140
setDateTime (TemporalHelper .toOffsetDateTime (LocalDateTime .parse (dateString .toString ())));
167
141
}
168
142
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 );
220
144
}
221
145
222
146
private static ZoneId toZoneId (BigDecimal offset ) {
@@ -280,17 +204,7 @@ private static boolean isZoneEquivalentToOffset(ZoneId zoneId, BigDecimal offset
280
204
281
205
final double zoneDouble = offsetHours .doubleValue ();
282
206
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 ;
294
208
}
295
209
296
210
public DateTime expandPartialMinFromPrecision (Precision thePrecision ) {
@@ -363,12 +277,8 @@ public Integer compare(BaseTemporal other, boolean forSort) {
363
277
public OffsetDateTime getNormalized (Precision precision ) {
364
278
return getNormalized (precision , zoneId );
365
279
}
366
- public OffsetDateTime getNormalized (Precision precision , ZoneId nullableZoneId ) {
367
280
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 ) {
372
282
if (precision .toDateTimeIndex () > Precision .DAY .toDateTimeIndex ()) {
373
283
if (nullableZoneId != null ) {
374
284
return dateTime .atZoneSameInstant (nullableZoneId ).toOffsetDateTime ();
@@ -392,25 +302,12 @@ public Integer compareToPrecision(BaseTemporal other, Precision thePrecision) {
392
302
393
303
// adjust dates to evaluation offset
394
304
OffsetDateTime leftDateTime = this .getNormalized (thePrecision );
395
- // LUKETODO; normalize to "this" zoneId?
396
305
OffsetDateTime rightDateTime = ((DateTime ) other ).getNormalized (thePrecision , getZoneId ());
397
306
398
307
if (!leftMeetsPrecisionRequirements || !rightMeetsPrecisionRequirements ) {
399
308
thePrecision = Precision .getLowestDateTimePrecision (this .precision , other .precision );
400
309
}
401
310
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
-
414
311
for (int i = 0 ; i < thePrecision .toDateTimeIndex () + 1 ; ++i ) {
415
312
int leftComp = leftDateTime .get (Precision .getDateTimeChronoFieldFromIndex (i ));
416
313
int rightComp = rightDateTime .get (Precision .getDateTimeChronoFieldFromIndex (i ));
0 commit comments