Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 68x 7x 7x 5x 5x 2x | /**
* Formats a duration in milliseconds for display, keeping two significant
* units at most: `824 ms`, `12.4 s`, `1 min 55 s`, `3 h 12 min`. Used for
* totals (which can span hours), where a raw millisecond count is unreadable.
*/
export function formatDuration(ms: number): string {
if (ms < 1000) return `${Math.round(ms)} ms`
const totalSeconds = ms / 1000
if (totalSeconds < 60) return `${totalSeconds.toFixed(1)} s`
const totalMinutes = Math.floor(totalSeconds / 60)
if (totalMinutes < 60) return `${totalMinutes} min ${Math.floor(totalSeconds % 60)} s`
return `${Math.floor(totalMinutes / 60)} h ${totalMinutes % 60} min`
}
|