Skip to content

Commit

Permalink
Deprecate DateTimeType.getZonedDateTime and introduce new overload wi…
Browse files Browse the repository at this point in the history
…th ZoneId

Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Dec 2, 2024
1 parent c542d83 commit 58353e8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private ZonedDateTime parseTime(@Nullable String sTime, Supplier<ZonedDateTime>
return defaultSupplier.get();
}
final DateTimeType dateTime = new DateTimeType(sTime);
return dateTime.getInstant().atZone(timeZoneProvider.getTimeZone());
return dateTime.getZonedDateTime(timeZoneProvider.getTimeZone());
}

@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void process(Type value) {
cronExpression = CronAdjuster.REBOOT;
} else if (value instanceof DateTimeType dateTimeType) {
boolean itemIsTimeOnly = dateTimeType.toString().startsWith("1970-01-01T");
cronExpression = dateTimeType.getInstant().atZone(ZoneId.systemDefault()).plusSeconds(offset.longValue())
cronExpression = dateTimeType.getZonedDateTime(ZoneId.systemDefault()).plusSeconds(offset.longValue())
.format(timeOnly || itemIsTimeOnly ? CRON_TIMEONLY_FORMATTER : CRON_FORMATTER);
startScheduler();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public Response httpPutPersistenceItemData(@Context HttpHeaders headers,

private ZonedDateTime convertTime(String sTime) {
DateTimeType dateTime = new DateTimeType(sTime);
return dateTime.getInstant().atZone(timeZoneProvider.getTimeZone());
return dateTime.getZonedDateTime(timeZoneProvider.getTimeZone());
}

private Response getItemHistoryDTO(@Nullable String serviceId, String itemName, @Nullable String timeBegin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,25 @@ public DateTimeType(String zonedValue) {
}

/**
* Get object represented as a {@link ZonedDateTime} with system
* default time-zone applied
* @deprecated
* Get object represented as a {@link ZonedDateTime} with system
* default time-zone applied
*
* @return a {@link ZonedDateTime} representation of the object
*/
@Deprecated
public ZonedDateTime getZonedDateTime() {
return instant.atZone(ZoneId.systemDefault());
return getZonedDateTime(ZoneId.systemDefault());
}

/**
* Get object represented as a {@link ZonedDateTime} with the
* the provided time-zone applied
*
* @return a {@link ZonedDateTime} representation of the object
*/
public ZonedDateTime getZonedDateTime(ZoneId zoneId) {
return instant.atZone(zoneId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,18 @@ public void zonedParsingTest() {
DateTimeType dt1 = new DateTimeType("2019-06-12T17:30:00Z");
DateTimeType dt2 = new DateTimeType("2019-06-12T17:30:00+0000");
DateTimeType dt3 = new DateTimeType("2019-06-12T19:30:00+0200");
DateTimeType dt4 = new DateTimeType("2019-06-12T19:30:00+0200");
assertThat(dt1, is(dt2));

ZonedDateTime zdt1 = dt1.getZonedDateTime();
ZonedDateTime zdt2 = dt2.getZonedDateTime();
ZonedDateTime zdt3 = dt3.getZonedDateTime();
ZonedDateTime zdt4 = dt4.getZonedDateTime(ZoneId.of("UTC"));
assertThat(zdt1.getZone(), is(zdt2.getZone()));
assertThat(zdt1, is(zdt2));
assertThat(zdt1, is(zdt3.withZoneSameInstant(zdt1.getZone())));
assertThat(zdt2, is(zdt3.withZoneSameInstant(zdt2.getZone())));
assertThat(zdt1, is(zdt4));
}

@Test
Expand Down

0 comments on commit 58353e8

Please sign in to comment.