diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java index 66a0578f2d6..aeb8e3ea7db 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java @@ -449,7 +449,7 @@ private Response getItemHistoryDTO(@Nullable String serviceId, String itemName, while (it.hasNext()) { HistoricItem historicItem = it.next(); State state = historicItem.getState(); - long timestamp = historicItem.getTimestamp().toInstant().toEpochMilli(); + long timestamp = historicItem.getInstant().toEpochMilli(); // For 'binary' states, we need to replicate the data // to avoid diagonal lines diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java index ff1ea858488..f61c2cc4b7b 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java @@ -12,6 +12,7 @@ */ package org.openhab.core.persistence; +import java.time.Instant; import java.time.ZonedDateTime; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -38,6 +39,15 @@ public interface HistoricItem { */ ZonedDateTime getTimestamp(); + /** + * returns the timestamp of the persisted item + * + * @return the timestamp of the item + */ + default Instant getInstant() { + return getTimestamp().toInstant(); + } + /** * returns the current state of the item * diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManagerImpl.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManagerImpl.java index e09678b3224..fe507de8982 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManagerImpl.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/internal/PersistenceManagerImpl.java @@ -577,8 +577,9 @@ public void scheduleNextPersistedForecastForItem(String itemName) { .build().query(filter).iterator(); while (result.hasNext()) { HistoricItem next = result.next(); - if (next.getTimestamp().isAfter(ZonedDateTime.now())) { - scheduleNextForecastForItem(itemName, next.getTimestamp().toInstant(), next.getState()); + Instant timestamp = next.getInstant(); + if (timestamp.isAfter(Instant.now())) { + scheduleNextForecastForItem(itemName, timestamp, next.getState()); break; } } diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java index 98d97287c43..09abb6f7718 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/chart/defaultchartprovider/DefaultChartProvider.java @@ -359,12 +359,12 @@ private boolean addItem(XYChart chart, QueryablePersistenceService service, Zone // For 'binary' states, we need to replicate the data // to avoid diagonal lines if (state instanceof OnOffType || state instanceof OpenClosedType) { - xData.add(Date.from(historicItem.getTimestamp().toInstant().minus(1, ChronoUnit.MILLIS))); + xData.add(Date.from(historicItem.getInstant().minus(1, ChronoUnit.MILLIS))); yData.add(convertData(state)); } state = historicItem.getState(); - xData.add(Date.from(historicItem.getTimestamp().toInstant())); + xData.add(Date.from(historicItem.getInstant())); yData.add(convertData(state)); }