Skip to content

Commit 2ded1d1

Browse files
jlaurlsiepel
authored andcommitted
Simplify DateTimeType handling for JDBC
Signed-off-by: Jacob Laursen <[email protected]>
1 parent b2c9abb commit 2ded1d1

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,7 @@ protected ItemVO storeItemValueProvider(Item item, State itemState, ItemVO vo) {
639639
break;
640640
case "DATETIMEITEM":
641641
vo.setValueTypes(getSqlTypes().get(itemType), java.sql.Timestamp.class);
642-
java.sql.Timestamp d = new java.sql.Timestamp(
643-
((DateTimeType) itemState).getZonedDateTime().toInstant().toEpochMilli());
642+
java.sql.Timestamp d = new java.sql.Timestamp(((DateTimeType) itemState).getInstant().toEpochMilli());
644643
logger.debug("JDBC::storeItemValueProvider: DateTimeItem: '{}'", d);
645644
vo.setValue(d);
646645
break;
@@ -684,7 +683,7 @@ protected State objectAsState(Item item, @Nullable Unit<? extends Quantity<?>> u
684683
}
685684
return unit == null ? DecimalType.valueOf(objectAsString(v)) : QuantityType.valueOf(objectAsString(v));
686685
} else if (item instanceof DateTimeItem) {
687-
return new DateTimeType(objectAsInstant(v).atZone(ZoneId.systemDefault()));
686+
return new DateTimeType(objectAsInstant(v));
688687
} else if (item instanceof ColorItem) {
689688
return HSBType.valueOf(objectAsString(v));
690689
} else if (item instanceof DimmerItem || item instanceof RollershutterItem) {

bundles/org.openhab.persistence.jdbc/src/test/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAOTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,11 @@ private static Stream<Arguments> provideTestCasesForObjectAsStateValid() {
127127
LocalDateTime.parse("2021-02-01T23:30:02.049"), null,
128128
DateTimeType.valueOf("2021-02-01T23:30:02.049")),
129129
Arguments.of(new DateTimeItem("Long_DateTimeItem"), Long.valueOf("1612222202049"), null,
130-
new DateTimeType(ZonedDateTime.ofInstant(Instant.parse("2021-02-01T23:30:02.049Z"),
131-
ZoneId.systemDefault()))),
130+
new DateTimeType(Instant.parse("2021-02-01T23:30:02.049Z"))),
132131
Arguments.of(new DateTimeItem("Date_DateTimeItem"), java.sql.Date.valueOf("2021-02-01"), null,
133132
DateTimeType.valueOf("2021-02-01T00:00:00.000")),
134133
Arguments.of(new DateTimeItem("Instant_DateTimeItem"), Instant.parse("2021-02-01T23:30:02.049Z"), null,
135-
new DateTimeType(ZonedDateTime.ofInstant(Instant.parse("2021-02-01T23:30:02.049Z"),
136-
ZoneId.systemDefault()))),
134+
new DateTimeType(Instant.parse("2021-02-01T23:30:02.049Z"))),
137135
Arguments.of(new DateTimeItem("String_DateTimeItem"), "2021-02-01 23:30:02.049", null,
138136
DateTimeType.valueOf("2021-02-01T23:30:02.049")));
139137
}

0 commit comments

Comments
 (0)