(epochMs: number)
| 1 | /** Format an epoch-ms timestamp as a short relative string ("2m ago", "3h ago"). */ |
| 2 | export function formatRelativeTime(epochMs: number): string { |
| 3 | if (!epochMs || !Number.isFinite(epochMs)) return '—'; |
| 4 | const diff = Date.now() - epochMs; |
| 5 | if (diff < 0) return 'just now'; |
| 6 | const s = Math.floor(diff / 1000); |
| 7 | if (s < 60) return `${s}s ago`; |
| 8 | const m = Math.floor(s / 60); |
| 9 | if (m < 60) return `${m}m ago`; |
| 10 | const h = Math.floor(m / 60); |
| 11 | if (h < 24) return `${h}h ago`; |
| 12 | const d = Math.floor(h / 24); |
| 13 | if (d < 30) return `${d}d ago`; |
| 14 | const mo = Math.floor(d / 30); |
| 15 | if (mo < 12) return `${mo}mo ago`; |
| 16 | return `${Math.floor(mo / 12)}y ago`; |
| 17 | } |
| 18 | |
| 19 | /** Format an epoch-ms timestamp as ISO-ish local time (YYYY-MM-DD HH:MM:SS). */ |
| 20 | export function formatAbsoluteTime(epochMs: number): string { |
no test coverage detected