17 lines
437 B
TypeScript
17 lines
437 B
TypeScript
export function formatDurationHuman(milliseconds: number): string {
|
|
const totalSeconds = Math.max(0, Math.floor(milliseconds / 1000))
|
|
const hours = Math.floor(totalSeconds / 3600)
|
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
|
const seconds = totalSeconds % 60
|
|
|
|
if (hours > 0) {
|
|
return `${hours}h ${minutes}m ${seconds}s`
|
|
}
|
|
|
|
if (minutes > 0) {
|
|
return `${minutes}m ${seconds}s`
|
|
}
|
|
|
|
return `${seconds}s`
|
|
}
|