Simplify DateTimeType handling for JDBC

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-14 22:23:26 +01:00 committed by lsiepel
parent b2c9abbe29
commit 2ded1d14c9
2 changed files with 4 additions and 7 deletions

View File

@ -639,8 +639,7 @@ public class JdbcBaseDAO {
break; break;
case "DATETIMEITEM": case "DATETIMEITEM":
vo.setValueTypes(getSqlTypes().get(itemType), java.sql.Timestamp.class); vo.setValueTypes(getSqlTypes().get(itemType), java.sql.Timestamp.class);
java.sql.Timestamp d = new java.sql.Timestamp( java.sql.Timestamp d = new java.sql.Timestamp(((DateTimeType) itemState).getInstant().toEpochMilli());
((DateTimeType) itemState).getZonedDateTime().toInstant().toEpochMilli());
logger.debug("JDBC::storeItemValueProvider: DateTimeItem: '{}'", d); logger.debug("JDBC::storeItemValueProvider: DateTimeItem: '{}'", d);
vo.setValue(d); vo.setValue(d);
break; break;
@ -684,7 +683,7 @@ public class JdbcBaseDAO {
} }
return unit == null ? DecimalType.valueOf(objectAsString(v)) : QuantityType.valueOf(objectAsString(v)); return unit == null ? DecimalType.valueOf(objectAsString(v)) : QuantityType.valueOf(objectAsString(v));
} else if (item instanceof DateTimeItem) { } else if (item instanceof DateTimeItem) {
return new DateTimeType(objectAsInstant(v).atZone(ZoneId.systemDefault())); return new DateTimeType(objectAsInstant(v));
} else if (item instanceof ColorItem) { } else if (item instanceof ColorItem) {
return HSBType.valueOf(objectAsString(v)); return HSBType.valueOf(objectAsString(v));
} else if (item instanceof DimmerItem || item instanceof RollershutterItem) { } else if (item instanceof DimmerItem || item instanceof RollershutterItem) {

View File

@ -127,13 +127,11 @@ public class JdbcBaseDAOTest {
LocalDateTime.parse("2021-02-01T23:30:02.049"), null, LocalDateTime.parse("2021-02-01T23:30:02.049"), null,
DateTimeType.valueOf("2021-02-01T23:30:02.049")), DateTimeType.valueOf("2021-02-01T23:30:02.049")),
Arguments.of(new DateTimeItem("Long_DateTimeItem"), Long.valueOf("1612222202049"), null, Arguments.of(new DateTimeItem("Long_DateTimeItem"), Long.valueOf("1612222202049"), null,
new DateTimeType(ZonedDateTime.ofInstant(Instant.parse("2021-02-01T23:30:02.049Z"), new DateTimeType(Instant.parse("2021-02-01T23:30:02.049Z"))),
ZoneId.systemDefault()))),
Arguments.of(new DateTimeItem("Date_DateTimeItem"), java.sql.Date.valueOf("2021-02-01"), null, Arguments.of(new DateTimeItem("Date_DateTimeItem"), java.sql.Date.valueOf("2021-02-01"), null,
DateTimeType.valueOf("2021-02-01T00:00:00.000")), DateTimeType.valueOf("2021-02-01T00:00:00.000")),
Arguments.of(new DateTimeItem("Instant_DateTimeItem"), Instant.parse("2021-02-01T23:30:02.049Z"), null, 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"), new DateTimeType(Instant.parse("2021-02-01T23:30:02.049Z"))),
ZoneId.systemDefault()))),
Arguments.of(new DateTimeItem("String_DateTimeItem"), "2021-02-01 23:30:02.049", null, Arguments.of(new DateTimeItem("String_DateTimeItem"), "2021-02-01 23:30:02.049", null,
DateTimeType.valueOf("2021-02-01T23:30:02.049"))); DateTimeType.valueOf("2021-02-01T23:30:02.049")));
} }