export function timeAgo(iso: string): string { const s = Math.max(0, (Date.now() - new Date(iso).getTime()) / 1000); if (s < 60) return 'just now'; if (s < 3600) return `${Math.floor(s / 60)}m ago`; if (s < 86400) return `${Math.floor(s / 3600)}h ago`; return `${Math.floor(s / 86400)}d ago`; } /** "until 5:30 PM", "until tomorrow 1:00 AM", or "until you turn it back on" for an indefinite pause. */ export function pausedUntilLabel(iso: string, now = new Date()): string { const until = new Date(iso); if (until.getTime() - now.getTime() > 30 * 86_400_000) return 'until you turn it back on'; const time = until.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' }); return until.toDateString() === now.toDateString() ? `until ${time}` : `until tomorrow ${time}`; }