const MINUTE = 60_000 const HOUR = 3_600_000 const DAY = 86_400_000 export function relativeTime(at: number | null | undefined): string { if (!at) return '' const diff = Date.now() - at if (diff < 45_000) return 'just now' if (diff < HOUR) return `${Math.max(1, Math.round(diff / MINUTE))}m ago` if (diff < DAY) return `${Math.round(diff / HOUR)}h ago` if (diff < 7 * DAY) return `${Math.round(diff / DAY)}d ago` return new Date(at).toLocaleDateString('en', { month: 'short', day: 'numeric' }) } export function fullTime(at: number | null | undefined): string { if (!at) return '' return new Date(at).toLocaleString('en', { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', }) } export function formatDate(at: number | null | undefined): string { if (!at) return '' return new Date(at).toLocaleDateString('en', { year: 'numeric', month: 'short', day: 'numeric' }) } export function formatSize(bytes: number): string { if (bytes < 1024) return `${bytes} B` if (bytes < 1024 * 1024) return `${Math.round((bytes / 1024) * 10) / 10} KB` return `${Math.round((bytes / (1024 * 1024)) * 10) / 10} MB` } export function initials(name: string): string { const parts = name.trim().split(/\s+/).filter(Boolean) if (parts.length === 0) return '?' const first = parts[0]?.[0] ?? '' const second = parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? '') : '' return (first + second).toUpperCase() } export function formatCost(cost: number | null | undefined): string { if (cost === null || cost === undefined) return '' if (cost === 0) return '$0.00' if (cost < 0.01) return `$${cost.toFixed(4)}` return `$${cost.toFixed(2)}` } export function plural(count: number, one: string, many: string): string { return count === 1 ? one : many }