Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[timer] Add Timer.getExecutionTime() #2147

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -60,5 +67,4 @@ public interface Timer {
* @return true, if the rescheduling was done successful
*/
public boolean reschedule(ZonedDateTime newTime);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down