fix(utils): clamped usage durations to suppress stale negative reset countdowns

- Clamped `formatDuration` to return `0ms` for non-positive, NaN, or infinite inputs.
- Updated usage report rendering to suppress reset countdowns when `resetsAt` is absent or no longer in the future.
- Added unit tests for `formatDuration` covering clamped values and standard duration formatting.
This commit is contained in:
can1357
2026-05-26 20:22:25 +02:00
parent c936620c63
commit 8a32eceb53
4 changed files with 36 additions and 5 deletions
@@ -1368,10 +1368,12 @@ function formatUnlimitedReportLabel(report: UsageReport, index: number): string
}
function formatResetShort(limit: UsageLimit, nowMs: number): string | undefined {
if (limit.window?.resetsAt !== undefined) {
return formatDuration(limit.window.resetsAt - nowMs);
}
return undefined;
const resetsAt = limit.window?.resetsAt;
if (resetsAt === undefined) return undefined;
// Codex returns the prior window's reset_at until a new request opens a fresh window —
// rendering a negative delta is meaningless, so drop the suffix in that case.
if (resetsAt <= nowMs) return undefined;
return formatDuration(resetsAt - nowMs);
}
function formatAccountHeaderRow(