Simplify DateTimeType handling for OpenUV

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-18 20:28:19 +01:00 committed by lsiepel
parent a989208cc6
commit 541f8d4028

View File

@ -14,8 +14,7 @@ package org.openhab.binding.openuv.internal.handler;
import static org.openhab.binding.openuv.internal.OpenUVBindingConstants.*; import static org.openhab.binding.openuv.internal.OpenUVBindingConstants.*;
import java.time.ZoneId; import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -100,8 +99,7 @@ public class OpenUVReportHandler extends BaseThingHandler {
if ((job == null || job.isCancelled())) { if ((job == null || job.isCancelled())) {
State uvMaxTime = openUVData.getUVMaxTime(); State uvMaxTime = openUVData.getUVMaxTime();
if (uvMaxTime instanceof DateTimeType uvMaxDateTime) { if (uvMaxTime instanceof DateTimeType uvMaxDateTime) {
long timeDiff = ChronoUnit.MINUTES.between(ZonedDateTime.now(ZoneId.systemDefault()), long timeDiff = ChronoUnit.MINUTES.between(Instant.now(), uvMaxDateTime.getInstant());
uvMaxDateTime.getZonedDateTime());
if (timeDiff > 0) { if (timeDiff > 0) {
logger.debug("Scheduling {} in {} minutes", UV_MAX_EVENT, timeDiff); logger.debug("Scheduling {} in {} minutes", UV_MAX_EVENT, timeDiff);
uvMaxJob = scheduler.schedule(() -> { uvMaxJob = scheduler.schedule(() -> {