[timer] Add Timer.getExecutionTime() (#2147)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng
2021-01-26 17:17:40 +01:00
committed by GitHub
parent 86a447c23a
commit 6de92ec6ef
2 changed files with 13 additions and 1 deletions
@@ -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);
}
@@ -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 class TimerImpl implements Timer {
}
}
@Override
public ZonedDateTime getExecutionTime() {
return cancelled ? null : ZonedDateTime.now().plusNanos(future.getDelay(TimeUnit.NANOSECONDS));
}
@Override
public boolean isActive() {
return !future.isDone() && !cancelled;