mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-25 19:46:36 +00:00
14 lines
427 B
JavaScript
14 lines
427 B
JavaScript
import durationToSeconds from '../datetime/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;
|
|
}
|