From d96e5d5bc01d19d9d11f782b4d1335237daf10e0 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Tue, 29 Nov 2022 10:25:53 -0700 Subject: [PATCH] return the precise scheduled execution time for timers (#3182) When writing tests and mocking time, it can be important that execution_time match _exactly_ with what was sent to reschedule(). When re-calculating based on now and the expected remaining delay, this might be off by a few milliseconds. We have the exact time that was requested already, so might as well use it. Signed-off-by: Cody Cutrer --- .../automation/module/script/internal/action/TimerImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/action/TimerImpl.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/action/TimerImpl.java index acc43a287f..73a1089ae2 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/action/TimerImpl.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/action/TimerImpl.java @@ -13,7 +13,6 @@ package org.openhab.core.automation.module.script.internal.action; import java.time.ZonedDateTime; -import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -64,7 +63,7 @@ public class TimerImpl implements Timer { @Override public @Nullable ZonedDateTime getExecutionTime() { - return future.isCancelled() ? null : ZonedDateTime.now().plusNanos(future.getDelay(TimeUnit.NANOSECONDS)); + return future.isCancelled() ? null : future.getScheduledTime(); } @Override