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;