mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 22:06:34 +00:00
Use finishes_at in timer remaining calculation (#22169)
* Use finishes_at in timer remaining calculation * lint * fix test
This commit is contained in:
parent
4c2044e70a
commit
ce9993fd36
@ -72,8 +72,8 @@ export const timerTimeRemaining = (
|
|||||||
|
|
||||||
if (stateObj.state === "active") {
|
if (stateObj.state === "active") {
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
const madeActive = new Date(stateObj.last_changed).getTime();
|
const finishes = new Date(stateObj.attributes.finishes_at).getTime();
|
||||||
timeRemaining = Math.max(timeRemaining - (now - madeActive) / 1000, 0);
|
timeRemaining = Math.max((finishes - now) / 1000, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return timeRemaining;
|
return timeRemaining;
|
||||||
|
@ -42,8 +42,8 @@ describe("timerTimeRemaining", () => {
|
|||||||
state: "active",
|
state: "active",
|
||||||
attributes: {
|
attributes: {
|
||||||
remaining: "0:01:05",
|
remaining: "0:01:05",
|
||||||
|
finishes_at: "2018-01-17T16:16:17+00:00",
|
||||||
},
|
},
|
||||||
last_changed: "2018-01-17T16:15:12Z",
|
|
||||||
} as any),
|
} as any),
|
||||||
47
|
47
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user