diff --git a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java index 4359dc8b6..1cc6eb9c1 100644 --- a/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java +++ b/bundles/org.openhab.persistence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java @@ -252,6 +252,12 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { @Override public Iterable query(FilterCriteria filter) { + ZonedDateTime filterBeginDate = filter.getBeginDate(); + ZonedDateTime filterEndDate = filter.getEndDate(); + if (filterBeginDate != null && filterEndDate != null && filterBeginDate.isAfter(filterEndDate)) { + throw new IllegalArgumentException("begin (" + filterBeginDate + ") before end (" + filterEndDate + ")"); + } + String itemName = filter.getItemName(); RrdDb db = null; @@ -280,14 +286,11 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { } long start = 0L; - // set end to {@link Instant#MAX} instead of current timestamp to enable requesting future time ranges including - // boundary values via REST API - // see discussion in https://github.com/openhab/openhab-addons/pull/14238 - long end = filter.getEndDate() == null ? Instant.MAX.getEpochSecond() - : filter.getEndDate().toInstant().getEpochSecond(); + long end = filterEndDate == null ? System.currentTimeMillis() / 1000 + : filterEndDate.toInstant().getEpochSecond(); try { - if (filter.getBeginDate() == null) { + if (filterBeginDate == null) { // as rrd goes back for years and gets more and more // inaccurate, we only support descending order // and a single return value @@ -296,7 +299,7 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { // query, which we want to support if (filter.getOrdering() == Ordering.DESCENDING && filter.getPageSize() == 1 && filter.getPageNumber() == 0) { - if (filter.getEndDate() == null) { + if (filterEndDate == null) { // we are asked only for the most recent value! double lastValue = db.getLastDatasourceValue(DATASOURCE_STATE); if (!Double.isNaN(lastValue)) { @@ -315,13 +318,13 @@ public class RRD4jPersistenceService implements QueryablePersistenceService { "rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested"); } } else { - start = filter.getBeginDate().toInstant().getEpochSecond(); + start = filterBeginDate.toInstant().getEpochSecond(); } // do not call method {@link RrdDb#createFetchRequest(ConsolFun, long, long, long)} if start > end to avoid // an IAE to be thrown if (start > end) { - logger.warn("Could not query rrd4j database for item '{}': start ({}) > end ({})", itemName, start, + logger.debug("Could not query rrd4j database for item '{}': start ({}) > end ({})", itemName, start, end); return List.of(); }