From 2d56704e3c5b646c29c7bccd92517faf62d022a0 Mon Sep 17 00:00:00 2001 From: Jimmy Tanagra Date: Sat, 23 Jan 2021 13:18:05 +1000 Subject: [PATCH] [timer] Add Timer.getExecutionTime() Signed-off-by: Jimmy Tanagra --- .../src/org/openhab/core/model/script/actions/Timer.java | 8 +++++++- .../core/model/script/internal/actions/TimerImpl.java | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Timer.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Timer.java index ce9881a273b..56d28015505 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Timer.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Timer.java @@ -30,6 +30,13 @@ public interface Timer { */ public boolean cancel(); + /** + * Gets the scheduled exection time + * + * @return the scheduled execution time, or null if the timer was cancelled + */ + public ZonedDateTime getExecutionTime(); + /** * Determines whether the scheduled execution is yet to happen. * @@ -60,5 +67,4 @@ public interface Timer { * @return true, if the rescheduling was done successful */ public boolean reschedule(ZonedDateTime newTime); - } diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/internal/actions/TimerImpl.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/internal/actions/TimerImpl.java index af8e8111ceb..26369888e98 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/internal/actions/TimerImpl.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/internal/actions/TimerImpl.java @@ -13,6 +13,7 @@ package org.openhab.core.model.script.internal.actions; import java.time.ZonedDateTime; +import java.util.concurrent.TimeUnit; import org.openhab.core.model.script.actions.Timer; import org.openhab.core.scheduler.ScheduledCompletableFuture; @@ -63,6 +64,11 @@ public boolean reschedule(ZonedDateTime newTime) { } } + @Override + public ZonedDateTime getExecutionTime() { + return cancelled ? null : ZonedDateTime.now().plusNanos(future.getDelay(TimeUnit.NANOSECONDS)); + } + @Override public boolean isActive() { return !future.isDone() && !cancelled;