(timestamp: number, now = Date.now())
| 7 | * clock. |
| 8 | */ |
| 9 | export const formatRelativeTime = (timestamp: number, now = Date.now()): string => { |
| 10 | const diffMs = Math.max(0, now - timestamp); |
| 11 | const minutes = Math.floor(diffMs / 60_000); |
| 12 | if (minutes < 1) return "just now"; |
| 13 | if (minutes < 60) return `${minutes}m ago`; |
| 14 | const hours = Math.floor(minutes / 60); |
| 15 | if (hours < 24) return `${hours}h ago`; |
| 16 | const days = Math.floor(hours / 24); |
| 17 | if (days < 7) return `${days}d ago`; |
| 18 | return new Date(timestamp).toLocaleDateString(undefined, { month: "short", day: "numeric" }); |
| 19 | }; |
no outgoing calls
no test coverage detected