// Small display helpers for the browse pages. Times here are DURATIONS and // SIZES -- readings, not judgements -- so wherever they are shown in colour it // is `--color-meter`, never a verdict hue. /** `1:40`, `0:49`, `12:03`. Renders a cut length the way the READMEs quote it. */ export function fmtDur(seconds: number): string { if (!Number.isFinite(seconds) || seconds <= 0) return "–"; const s = Math.round(seconds); return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`; } export function fmtBytes(n: number): string { if (!n) return "–"; const mb = n / (1 << 20); return mb >= 1000 ? `${(mb / 1024).toFixed(1)} GB` : `${mb.toFixed(1)} MB`; } const MIN = 60_000; const HOUR = 60 * MIN; const DAY = 24 * HOUR; /** How long ago, coarsely. "which of these did I just rebuild" is the question. */ export function fmtAgo(mtimeMs: number, now = Date.now()): string { if (!mtimeMs) return "–"; const d = Math.max(0, now - mtimeMs); if (d < MIN) return "just now"; if (d < HOUR) return `${Math.floor(d / MIN)}m ago`; if (d < DAY) return `${Math.floor(d / HOUR)}h ago`; return `${Math.floor(d / DAY)}d ago`; }