11 lines
518 B
TypeScript
11 lines
518 B
TypeScript
/** Format a duration in seconds as a short human label, e.g. "3m 12s" or "1h 04m", for !stuck. */
|
|
export function formatDuration(totalSeconds: number): string {
|
|
const seconds = Math.max(0, Math.floor(totalSeconds));
|
|
const hours = Math.floor(seconds / 3600);
|
|
const minutes = Math.floor((seconds % 3600) / 60);
|
|
const secs = seconds % 60;
|
|
|
|
if (hours > 0) return `${hours}h ${String(minutes).padStart(2, '0')}m`;
|
|
if (minutes > 0) return `${minutes}m ${String(secs).padStart(2, '0')}s`;
|
|
return `${secs}s`;
|
|
}
|