@Override
public Iterable<HistoricItem> 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;
}
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
// 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)) {
"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();
}