mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-21 17:46: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
17 lines
407 B
JavaScript
17 lines
407 B
JavaScript
const leftPad = number => (number < 10 ? `0${number}` : number);
|
|
|
|
export default function secondsToDuration(d) {
|
|
const h = Math.floor(d / 3600);
|
|
const m = Math.floor((d % 3600) / 60);
|
|
const s = Math.floor(d % 3600 % 60);
|
|
|
|
if (h > 0) {
|
|
return `${h}:${leftPad(m)}:${leftPad(s)}`;
|
|
} else if (m > 0) {
|
|
return `${m}:${leftPad(s)}`;
|
|
} else if (s > 0) {
|
|
return '' + s;
|
|
}
|
|
return null;
|
|
}
|