fix(ui): show <1m for sub-minute quota reset windows instead of 0m (#108009)

* fix(ui): show <1m for sub-minute quota reset windows instead of 0m

formatQuotaReset computed Math.floor(diffMs / 60_000) for the minute branch.
When a provider quota window resets in under 60 seconds (common for 5h Anthropic
or 3h Codex windows near rollover), the floor is 0 and the UI rendered
"Resets in 0m" — nonsensical and indistinguishable from "already reset".

Add a sub-minute guard returning "<1m", matching the convention already used
by formatRemainingShort and formatRelativeTimestamp elsewhere in the codebase.

Co-Authored-By: Claude <noreply@anthropic.com>

* test(ui): cover quota reset display boundary

Co-Authored-By: ZCode <noreply@zcode.ai>

* test(ui): cover elapsed quota reset boundary

Co-Authored-By: ZCode <noreply@zcode.ai>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: ZCode <noreply@zcode.ai>
This commit is contained in:
Miorbnli
2026-07-15 16:15:36 +08:00
committed by GitHub
parent ac95af2c41
commit 9e6cce6358
2 changed files with 13 additions and 0 deletions
+10
View File
@@ -15,6 +15,16 @@ describe("formatQuotaReset", () => {
expect(formatQuotaReset(Date.now() + 2 * 60 * 60_000 + 15 * 60_000)).toBe("2h 15m");
});
it("returns <1m for sub-minute reset windows instead of 0m", () => {
vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-05-30T12:00:00.000Z"));
expect(formatQuotaReset(Date.now() - 1)).toBe("now");
expect(formatQuotaReset(Date.now())).toBe("now");
expect(formatQuotaReset(Date.now() + 1)).toBe("<1m");
expect(formatQuotaReset(Date.now() + 59_999)).toBe("<1m");
expect(formatQuotaReset(Date.now() + 60_000)).toBe("1m");
});
it("ignores Date-invalid reset timestamps", () => {
expect(formatQuotaReset(8_640_000_000_000_001)).toBeNull();
expect(formatQuotaReset(Number.POSITIVE_INFINITY)).toBeNull();
+3
View File
@@ -12,6 +12,9 @@ export function formatQuotaReset(resetAt?: number): string | null {
return "now";
}
const minutes = Math.floor(diffMs / 60_000);
if (minutes < 1) {
return "<1m";
}
if (minutes < 60) {
return `${minutes}m`;
}