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 05:05:01 -07:00 committed by GitHub
parent 4c2044e70a
commit ce9993fd36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

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;

View File

@ -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
);