| 120 | } |
| 121 | |
| 122 | function formatRelativeTime(dateString: string): string { |
| 123 | const diffMs = new Date(dateString).getTime() - Date.now(); |
| 124 | const absMs = Math.abs(diffMs); |
| 125 | const units = [ |
| 126 | { size: 24 * 60 * 60 * 1000, label: "d" }, |
| 127 | { size: 60 * 60 * 1000, label: "h" }, |
| 128 | { size: 60 * 1000, label: "m" }, |
| 129 | ]; |
| 130 | |
| 131 | for (const unit of units) { |
| 132 | if (absMs >= unit.size) { |
| 133 | const value = Math.round(absMs / unit.size); |
| 134 | return diffMs >= 0 ? `in ${value}${unit.label}` : `${value}${unit.label} ago`; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return diffMs >= 0 ? "any moment now" : "just now"; |
| 139 | } |
| 140 | |
| 141 | function formatDuration(durationMs?: number | null): string { |
| 142 | if (typeof durationMs !== "number" || Number.isNaN(durationMs)) { |