1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-24 04:39:01 +00:00
Files
frontend/src/common/datetime/seconds_to_duration.js
Paulus Schoutsen f70c0aea6c Org files (#1183)
* Organize files

* Import EventsMixin

* Import NavigateMixin

* Dissolve window.hassMixins

* Apply ElementMixin when we use it

* Update tests to point at right dir

* Eslint

* Clean

* Update mixins inside hassio

* Update lint command"

* Fix polymer lint
2018-05-16 13:47:34 -04:00

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;
}