Skip to content

Commit

Permalink
use TimeZoneProvider in PersistenceExtensions
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Feb 18, 2025
1 parent 38241a6 commit e4a69cf
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ private static void internalPersist(Item item, TimeSeries timeSeries, @Nullable
int startPage = 0;
filter.setPageNumber(startPage);

TimeZoneProvider tzProvider = timeZoneProvider;
ZoneId timeZone = tzProvider != null ? tzProvider.getTimeZone() : ZoneId.systemDefault();

Iterable<HistoricItem> items = qService.query(filter);
while (items != null) {
Iterator<HistoricItem> itemIterator = items.iterator();
Expand All @@ -478,7 +481,7 @@ private static void internalPersist(Item item, TimeSeries timeSeries, @Nullable
// Last persisted state value different from current state value, so it must have updated
// since last persist. We do not know when from persistence, so get it from the item.
return Optional.ofNullable(item.getLastStateUpdate())
.map(instant -> instant.atZone(ZoneId.systemDefault())).orElse(null);
.map(instant -> instant.atZone(timeZone)).orElse(null);
}
return historicItem.getTimestamp();
} else {
Expand All @@ -490,7 +493,7 @@ private static void internalPersist(Item item, TimeSeries timeSeries, @Nullable
return historicItem.getTimestamp();
} else {
return Optional.ofNullable(item.getLastStateChange())
.map(instant -> instant.atZone(ZoneId.systemDefault())).orElse(null);
.map(instant -> instant.atZone(timeZone)).orElse(null);
}
}
while (historicItem.getState().equals(state) && itemIterator.hasNext()) {
Expand Down

0 comments on commit e4a69cf

Please sign in to comment.