Simplify DateTimeType handling for Java Persistence API

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

View File

@ -142,8 +142,7 @@ public class JpaHistoricItem implements HistoricItem {
} else if (item instanceof RollershutterItem) { } else if (item instanceof RollershutterItem) {
state = PercentType.valueOf(pItem.getValue()); state = PercentType.valueOf(pItem.getValue());
} else if (item instanceof DateTimeItem) { } else if (item instanceof DateTimeItem) {
state = new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(pItem.getValue())), state = new DateTimeType(Instant.ofEpochMilli(Long.parseLong(pItem.getValue())));
ZoneId.systemDefault()));
} else if (item instanceof LocationItem) { } else if (item instanceof LocationItem) {
PointType pType = null; PointType pType = null;
String[] comps = pItem.getValue().split(";"); String[] comps = pItem.getValue().split(";");

View File

@ -37,7 +37,7 @@ public class StateHelper {
*/ */
public static String toString(State state) { public static String toString(State state) {
if (state instanceof DateTimeType type) { if (state instanceof DateTimeType type) {
return String.valueOf(type.getZonedDateTime().toInstant().toEpochMilli()); return String.valueOf(type.getInstant().toEpochMilli());
} }
if (state instanceof DecimalType type) { if (state instanceof DecimalType type) {
return String.valueOf(type.doubleValue()); return String.valueOf(type.doubleValue());