/** Compact elapsed time, e.g. `850ms`, `12.4s`, `3m 5s`, `2h 10m` or `1d 4h`. */ export function duration(input: number) { if (input < 1000) { return `${input}ms` } if (input < 60000) { return `${(input / 1000).toFixed(1)}s` } if (input < 3600000) { const minutes = Math.floor(input / 60000) const seconds = Math.floor((input % 60000) / 1000) return `${minutes}m ${seconds}s` } if (input < 86400000) { const hours = Math.floor(input / 3600000) const minutes = Math.floor((input % 3600000) / 60000) return `${hours}h ${minutes}m` } const days = Math.floor(input / 86400000) const hours = Math.floor((input % 86400000) / 3600000) return `${days}d ${hours}h` }