(val: string)
| 142 | } |
| 143 | |
| 144 | export function formatResetTime(val: string): string { |
| 145 | let normalised = val; |
| 146 | // ISO with nano precision → trim to ms for JS Date. |
| 147 | if (normalised.includes('.') && normalised.endsWith('Z')) { |
| 148 | const [base, frac] = normalised.slice(0, -1).split('.'); |
| 149 | if (base !== undefined && frac !== undefined) { |
| 150 | normalised = `${base}.${frac.slice(0, 3)}Z`; |
| 151 | } |
| 152 | } |
| 153 | const parsed = Date.parse(normalised); |
| 154 | if (!Number.isFinite(parsed)) return `resets at ${val}`; |
| 155 | const diffSec = Math.floor((parsed - Date.now()) / 1000); |
| 156 | if (diffSec <= 0) return 'reset'; |
| 157 | return `resets in ${formatDuration(diffSec)}`; |
| 158 | } |
| 159 | |
| 160 | export function formatDuration(totalSeconds: number): string { |
| 161 | if (!Number.isFinite(totalSeconds) || totalSeconds <= 0) return '0s'; |
no test coverage detected