From c174a18a4aba76328dfc5ec7cbae7bd591ffca7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Thu, 12 Sep 2024 09:29:35 +0200 Subject: [PATCH] FIX: nextFuzzyTimestamp in past --- .../homeautomation/schedule/entry/ScheduleEntry.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/ph87/homeautomation/schedule/entry/ScheduleEntry.java b/src/main/java/de/ph87/homeautomation/schedule/entry/ScheduleEntry.java index e227628..1e1c750 100644 --- a/src/main/java/de/ph87/homeautomation/schedule/entry/ScheduleEntry.java +++ b/src/main/java/de/ph87/homeautomation/schedule/entry/ScheduleEntry.java @@ -92,12 +92,14 @@ public class ScheduleEntry { public void setNextClearTimestamp(final ZonedDateTime next) { nextClearTimestamp = next; - if (nextClearTimestamp == null) { - nextFuzzyTimestamp = null; - } else { + nextFuzzyTimestamp = null; + if (nextClearTimestamp != null) { final int rangeFull = 2 * fuzzySeconds; - final int fuzzySeconds = rangeFull > 0 ? RANDOM.nextInt(rangeFull) - this.fuzzySeconds : 0; - nextFuzzyTimestamp = nextClearTimestamp.plusSeconds(fuzzySeconds); + final ZonedDateTime min = ZonedDateTime.now().plusMinutes(1); + while (nextFuzzyTimestamp == null || nextFuzzyTimestamp.isBefore(min)) { + final int fuzzySeconds = rangeFull > 0 ? RANDOM.nextInt(rangeFull) - this.fuzzySeconds : 0; + nextFuzzyTimestamp = nextClearTimestamp.plusSeconds(fuzzySeconds); + } } }