/** * Format a position-recorded timestamp as a human-readable "age" string. * * - < 5 s → "now" * - < 60 s → "Ns ago" * - < 1 hr → "Nm ago" * - else → wall-clock time ("HH:MM") * * Used by the connection chip ("last live HH:MM") and by Phase 3.4's * per-device detail panel. */ export function formatLastSeen(ts: number, now: number = Date.now()): string { const ageMs = Math.max(0, now - ts); if (ageMs < 5_000) return 'now'; if (ageMs < 60_000) return `${Math.floor(ageMs / 1000)}s ago`; if (ageMs < 60 * 60_000) return `${Math.floor(ageMs / 60_000)}m ago`; const d = new Date(ts); return d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }); }