Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend HistoricItem to work with Instant instead of ZonedDateTime #4384

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
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