mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-27 12:36:34 +00:00

* Add timer card and badge * Disable interval on disconnect * Tests! * One more test case * Remove padStart * Remove state from timer state card
14 lines
417 B
JavaScript
14 lines
417 B
JavaScript
import durationToSeconds from './duration_to_seconds.js';
|
|
|
|
export default function timerTimeRemaining(stateObj) {
|
|
let timeRemaining = durationToSeconds(stateObj.attributes.remaining);
|
|
|
|
if (stateObj.state === 'active') {
|
|
const now = new Date();
|
|
const madeActive = new Date(stateObj.last_changed);
|
|
timeRemaining = Math.max(timeRemaining - ((now - madeActive) / 1000), 0);
|
|
}
|
|
|
|
return timeRemaining;
|
|
}
|