From 253f36abbf3ac5e9f5b0657ffc9b4f995c45947c Mon Sep 17 00:00:00 2001 From: Hilbrand Bouwkamp Date: Thu, 30 Dec 2021 13:49:43 +0100 Subject: [PATCH] [astro] Fixed timeLeft calculation at the end of the year (#11889) Season timeleft calculated the wrong time at the end of the year, because the seasons it measures the time with are the seasons within the same year. So for times at the end of the year it computed against the season at the beginning of the year, resulting in negative number of days. Also changed the time of timeLeft to actual days instead of quantity unit days. Because with the milliseconds internal resolution it will generate events each and every time this channel is updated as milliseconds change often. Signed-off-by: Hilbrand Bouwkamp --- .../binding/astro/internal/model/Season.java | 13 ++++---- .../astro/internal/util/DateTimeUtils.java | 9 ++++- .../internal/util/DateTimeUtilsTest.java | 33 +++++++++++-------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java index e2f3e4418..00cfa2752 100644 --- a/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java +++ b/bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/model/Season.java @@ -12,8 +12,8 @@ */ package org.openhab.binding.astro.internal.model; -import static org.openhab.core.library.unit.MetricPrefix.MILLI; - +import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.Calendar; import javax.measure.quantity.Time; @@ -127,9 +127,10 @@ public class Season { * Returns the time left for current season */ public QuantityType