File
Blob: src/client/lib/format-date.ts
| 1 | export function formatRelativeDate(iso: string): string { |
| 2 | const date = new Date(iso); |
| 3 | const now = new Date(); |
| 4 | const diffMs = now.getTime() - date.getTime(); |
| 5 | if (diffMs < 0) return "Today"; |
| 6 | const diffDays = Math.floor(diffMs / 86400000); |
| 7 | if (diffDays === 0) return "Today"; |
| 8 | if (diffDays === 1) return "Yesterday"; |
| 9 | if (diffDays < 30) return `${diffDays}d ago`; |
| 10 | const diffMonths = Math.floor(diffDays / 30); |
| 11 | if (diffMonths < 12) return `${diffMonths}mo ago`; |
| 12 | return date.toLocaleDateString(); |
| 13 | } |
| 14 | |
| 15 | const ABSOLUTE_FORMATTER = new Intl.DateTimeFormat(undefined, { |
| 16 | year: "numeric", |
| 17 | month: "short", |
| 18 | day: "numeric", |
| 19 | hour: "numeric", |
| 20 | minute: "2-digit", |
| 21 | }); |
| 22 | |
| 23 | export function formatAbsoluteDate(iso: string): string { |
| 24 | return ABSOLUTE_FORMATTER.format(new Date(iso)); |
| 25 | } |