Skip to content

Commit

Permalink
Simplify DateTimeType handling for JDBC
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Nov 15, 2024
1 parent 48c26cf commit ce6fb84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,7 @@ protected ItemVO storeItemValueProvider(Item item, State itemState, ItemVO vo) {
break;
case "DATETIMEITEM":
vo.setValueTypes(getSqlTypes().get(itemType), java.sql.Timestamp.class);
java.sql.Timestamp d = new java.sql.Timestamp(
((DateTimeType) itemState).getZonedDateTime().toInstant().toEpochMilli());
java.sql.Timestamp d = new java.sql.Timestamp(((DateTimeType) itemState).getInstant().toEpochMilli());
logger.debug("JDBC::storeItemValueProvider: DateTimeItem: '{}'", d);
vo.setValue(d);
break;
Expand Down Expand Up @@ -684,7 +683,7 @@ protected State objectAsState(Item item, @Nullable Unit<? extends Quantity<?>> u
}
return unit == null ? DecimalType.valueOf(objectAsString(v)) : QuantityType.valueOf(objectAsString(v));
} else if (item instanceof DateTimeItem) {
return new DateTimeType(objectAsInstant(v).atZone(ZoneId.systemDefault()));
return new DateTimeType(objectAsInstant(v));
} else if (item instanceof ColorItem) {
return HSBType.valueOf(objectAsString(v));
} else if (item instanceof DimmerItem || item instanceof RollershutterItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,11 @@ private static Stream<Arguments> provideTestCasesForObjectAsStateValid() {
LocalDateTime.parse("2021-02-01T23:30:02.049"), null,
DateTimeType.valueOf("2021-02-01T23:30:02.049")),
Arguments.of(new DateTimeItem("Long_DateTimeItem"), Long.valueOf("1612222202049"), null,
new DateTimeType(ZonedDateTime.ofInstant(Instant.parse("2021-02-01T23:30:02.049Z"),
ZoneId.systemDefault()))),
new DateTimeType(Instant.parse("2021-02-01T23:30:02.049Z"))),
Arguments.of(new DateTimeItem("Date_DateTimeItem"), java.sql.Date.valueOf("2021-02-01"), null,
DateTimeType.valueOf("2021-02-01T00:00:00.000")),
Arguments.of(new DateTimeItem("Instant_DateTimeItem"), Instant.parse("2021-02-01T23:30:02.049Z"), null,
new DateTimeType(ZonedDateTime.ofInstant(Instant.parse("2021-02-01T23:30:02.049Z"),
ZoneId.systemDefault()))),
new DateTimeType(Instant.parse("2021-02-01T23:30:02.049Z"))),
Arguments.of(new DateTimeItem("String_DateTimeItem"), "2021-02-01 23:30:02.049", null,
DateTimeType.valueOf("2021-02-01T23:30:02.049")));
}
Expand Down

0 comments on commit ce6fb84

Please sign in to comment.