(timestamp: number)
| 7 | * formatUnixTimestamp(1735555200) // "Dec 30, 2024" |
| 8 | */ |
| 9 | export function formatUnixTimestamp(timestamp: number): string { |
| 10 | const date = new Date(timestamp * 1000); |
| 11 | const now = new Date(); |
| 12 | |
| 13 | // If it's today, show time |
| 14 | if (isToday(date)) { |
| 15 | return formatTime(date); |
| 16 | } |
| 17 | |
| 18 | // If it's yesterday |
| 19 | if (isYesterday(date)) { |
| 20 | return `Yesterday, ${formatTime(date)}`; |
| 21 | } |
| 22 | |
| 23 | // If it's within the last week, show day of week |
| 24 | if (isWithinWeek(date)) { |
| 25 | return `${getDayName(date)}, ${formatTime(date)}`; |
| 26 | } |
| 27 | |
| 28 | // If it's this year, don't show year |
| 29 | if (date.getFullYear() === now.getFullYear()) { |
| 30 | return date.toLocaleDateString('en-US', { |
| 31 | month: 'short', |
| 32 | day: 'numeric' |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | // Otherwise show full date |
| 37 | return date.toLocaleDateString('en-US', { |
| 38 | month: 'short', |
| 39 | day: 'numeric', |
| 40 | year: 'numeric' |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Formats an ISO timestamp string to a human-readable date |
no test coverage detected