export function formatCost(usd: number): string { if (usd < 0.01) return `$${usd.toFixed(4)}` if (usd < 1) return `$${usd.toFixed(3)}` return `$${usd.toFixed(2)}` } export function formatTokens(n: number): string { if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(1)}B` if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M` if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K` return n.toString() } export function formatDuration(minutes: number): string { if (minutes < 60) return `${Math.round(minutes)}m` const hours = Math.floor(minutes / 60) const mins = Math.round(minutes % 60) if (hours < 24) return `${hours}h ${mins}m` const days = Math.floor(hours / 24) const remainingHours = hours % 24 return `${days}d ${remainingHours}h` } export function formatNumber(n: number): string { return n.toLocaleString() } // Local-timezone YYYY-MM-DD bucket. Matches ccusage's _date-utils.ts so daily // totals agree to the cent — UTC slicing shifts cross-midnight tokens. const LOCAL_DATE_FORMATTER = new Intl.DateTimeFormat('en-CA', { year: 'numeric', month: '2-digit', day: '2-digit', }) export function formatLocalDate(d: Date): string { return LOCAL_DATE_FORMATTER.format(d) }