15 lines
341 B
TypeScript
15 lines
341 B
TypeScript
|
|
function pad(n: number) {
|
||
|
|
return String(n).padStart(2, '0')
|
||
|
|
}
|
||
|
|
|
||
|
|
export function fmt(secs: number) {
|
||
|
|
if (!secs || Number.isNaN(secs)) return '0:00'
|
||
|
|
const s = Math.floor(secs)
|
||
|
|
const m = Math.floor(s / 60)
|
||
|
|
const h = Math.floor(m / 60)
|
||
|
|
if (h > 0) {
|
||
|
|
return `${h}:${pad(m % 60)}:${pad(s % 60)}`
|
||
|
|
}
|
||
|
|
return `${m}:${pad(s % 60)}`
|
||
|
|
}
|