const MINUTE = 60_000; const HOUR = 3_600_000; const DAY = 86_400_000; export function relativeTime(dateStr: string): string { const now = Date.now(); const then = new Date(dateStr).getTime(); const diff = now - then; if (diff < MINUTE) { return "just now"; } if (diff < HOUR) { const mins = Math.floor(diff / MINUTE); return `${mins}m ago`; } if (diff < DAY) { const hours = Math.floor(diff / HOUR); return `${hours}h ago`; } if (diff < 7 * DAY) { const days = Math.floor(diff / DAY); return `${days}d ago`; } return new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric", }).format(new Date(dateStr)); } export function fullDate(dateStr: string): string { return new Date(dateStr).toLocaleString(); } export function formatCountdown(expiresAt: string): string { const diff = new Date(expiresAt).getTime() - Date.now(); if (diff <= 0) { return "Expired"; } const hours = Math.floor(diff / HOUR); const mins = Math.floor((diff % HOUR) / MINUTE); if (hours > 0) { return `${hours}h ${mins}m remaining`; } return `${mins}m remaining`; }