frontend/js/common/util/seconds_to_duration.js
Paulus Schoutsen 783f356679
Add timer card and badge (#810)
* Add timer card and badge

* Disable interval on disconnect

* Tests!

* One more test case

* Remove padStart

* Remove state from timer state card
2018-01-19 09:26:06 -08: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;
}