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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user