Skip to content

Commit

Permalink
Extend HistoricItem to work with Instant instead of ZonedDateTime (#4384
Browse files Browse the repository at this point in the history
)

Signed-off-by: Jörg Sautter <[email protected]>
  • Loading branch information
joerg1985 authored Oct 16, 2024
1 parent 389f6a3 commit af35487
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.openhab.core.persistence;

import java.time.Instant;
import java.time.ZonedDateTime;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand All @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit af35487

Please sign in to comment.