export function formatStage(stage: string): string { return stage .split("_") .map((w) => w.charAt(0).toUpperCase() + w.slice(1)) .join(" "); } export function timeAgo(iso: string): string { const diffMs = Date.now() - new Date(iso).getTime(); const sec = Math.round(diffMs / 1000); if (sec < 5) return "just now"; if (sec < 60) return `${sec}s ago`; const min = Math.round(sec / 60); if (min < 60) return `${min}m ago`; const hr = Math.round(min / 60); if (hr < 24) return `${hr}h ago`; const day = Math.round(hr / 24); return `${day}d ago`; } /** The calendar date a row belongs to — "12 Aug", or "12 Aug 2025" once it is * not this year. `timeAgo` answers "how long", which is not the same question as * "which day", and a list filtered by date needs the second one. */ export function formatDate(iso: string): string { const d = new Date(iso); if (Number.isNaN(d.getTime())) return ""; const sameYear = d.getFullYear() === new Date().getFullYear(); return d.toLocaleDateString(undefined, { day: "numeric", month: "short", ...(sameYear ? {} : { year: "numeric" }), }); } /** "≈$1.23 est." — a recorded media estimate, never an invoice. */ export const formatUsd = (usd: number) => `≈$${usd.toFixed(2)}`;