mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
[timer] Add Timer.getExecutionTime() (#2147)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
+7
-1
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
+6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user