flybrain/services/bridge/src/duration.ts
acamilo 660c3cf00d
Some checks failed
ci / node 22 (test + typecheck) (push) Has been cancelled
ci / rust stable (cargo test --workspace --release) (push) Has been cancelled
ci / infra/tests/lint.sh (push) Has been cancelled
ci / playwright apps/stage (allowed to fail) (push) Has been cancelled
flybrain v0.4.0: public tree (history retained privately)
2026-09-21 15:09:46 +00:00

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`;
}