diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java index 16b1af647..a0fefaba2 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java @@ -542,15 +542,15 @@ public class JdbcBaseDAO { protected String resolveTimeFilter(FilterCriteria filter, ZoneId timeZone) { String filterString = ""; - if (filter.getBeginDate() != null) { + ZonedDateTime beginDate = filter.getBeginDate(); + if (beginDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME>='" + JDBC_DATE_FORMAT.format(filter.getBeginDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME>='" + JDBC_DATE_FORMAT.format(beginDate.withZoneSameInstant(timeZone)) + "'"; } - if (filter.getEndDate() != null) { + ZonedDateTime endDate = filter.getEndDate(); + if (endDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME<='" + JDBC_DATE_FORMAT.format(filter.getEndDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME<='" + JDBC_DATE_FORMAT.format(endDate.withZoneSameInstant(timeZone)) + "'"; } return filterString; } diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java index 527e673ed..10045d1ed 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java @@ -242,15 +242,15 @@ public class JdbcDerbyDAO extends JdbcBaseDAO { StringUtilsExt.filterToString(filter), numberDecimalcount, table, simpleName); String filterString = ""; - if (filter.getBeginDate() != null) { + ZonedDateTime beginDate = filter.getBeginDate(); + if (beginDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME>='" + JDBC_DATE_FORMAT.format(filter.getBeginDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME>='" + JDBC_DATE_FORMAT.format(beginDate.withZoneSameInstant(timeZone)) + "'"; } - if (filter.getEndDate() != null) { + ZonedDateTime endDate = filter.getEndDate(); + if (endDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME<='" + JDBC_DATE_FORMAT.format(filter.getEndDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME<='" + JDBC_DATE_FORMAT.format(endDate.withZoneSameInstant(timeZone)) + "'"; } filterString += (filter.getOrdering() == Ordering.ASCENDING) ? " ORDER BY time ASC" : " ORDER BY time DESC"; if (filter.getPageSize() != 0x7fffffff) { diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java index 3043354b0..8add63026 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java @@ -260,15 +260,15 @@ public class JdbcPostgresqlDAO extends JdbcBaseDAO { filter.toString(), numberDecimalcount, table, simpleName); String filterString = ""; - if (filter.getBeginDate() != null) { + ZonedDateTime beginDate = filter.getBeginDate(); + if (beginDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME>='" + JDBC_DATE_FORMAT.format(filter.getBeginDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME>='" + JDBC_DATE_FORMAT.format(beginDate.withZoneSameInstant(timeZone)) + "'"; } - if (filter.getEndDate() != null) { + ZonedDateTime endDate = filter.getEndDate(); + if (endDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME<='" + JDBC_DATE_FORMAT.format(filter.getEndDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME<='" + JDBC_DATE_FORMAT.format(endDate.withZoneSameInstant(timeZone)) + "'"; } filterString += (filter.getOrdering() == Ordering.ASCENDING) ? " ORDER BY time ASC" : " ORDER BY time DESC"; if (filter.getPageSize() != 0x7fffffff) {