Use finishes_at in timer remaining calculation (#22169)

* Use finishes_at in timer remaining calculation

* lint

* fix test
This commit is contained in:
karwosts
2024-10-01 14:05:01 +02:00
committed by GitHub
parent 4c2044e70a
commit ce9993fd36
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -72,8 +72,8 @@ export const timerTimeRemaining = (
if (stateObj.state === "active") {
const now = new Date().getTime();
const madeActive = new Date(stateObj.last_changed).getTime();
timeRemaining = Math.max(timeRemaining - (now - madeActive) / 1000, 0);
const finishes = new Date(stateObj.attributes.finishes_at).getTime();
timeRemaining = Math.max((finishes - now) / 1000, 0);
}
return timeRemaining;
@@ -42,8 +42,8 @@ describe("timerTimeRemaining", () => {
state: "active",
attributes: {
remaining: "0:01:05",
finishes_at: "2018-01-17T16:16:17+00:00",
},
last_changed: "2018-01-17T16:15:12Z",
} as any),
47
);