Spaces:
Running
Running
File size: 558 Bytes
f27679f f42b4a1 ac7030c f27679f ac7030c f27679f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import { intervalToDuration } from 'date-fns'
import { isValidNumber } from '../utils/isValidNumber'
export function formatDuration(seconds: number): string {
if (!isValidNumber(seconds)) {
return '0:0'
}
const duration = intervalToDuration({ start: 0, end: seconds * 1000 })
const zeroPad = (num: any) => String(num).padStart(2, '0')
if (!isValidNumber(duration.minutes) || !isValidNumber(duration.seconds)) {
return '00:00'
}
const formatted = `${zeroPad(duration.minutes)}:${zeroPad(duration.seconds)}`
return formatted
} |