/** * Shared formatting utilities */ /** * Format bytes to human-readable size (B, KB, MB) */ export function formatSize(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } /** * Format ISO date to relative time (e.g., "2 hours ago") */ export function formatRelativeTime(isoDate: string): string { const date = new Date(isoDate); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const seconds = Math.floor(diffMs / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); const days = Math.floor(hours / 24); if (days > 365) return `${Math.floor(days / 365)}y ago`; if (days > 30) return `${Math.floor(days / 30)}mo ago`; if (days > 0) return `${days}d ago`; if (hours > 0) return `${hours}h ago`; if (minutes > 0) return `${minutes}m ago`; return "just now"; }