mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
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:
@@ -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();
|
||||
|
||||
@@ -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`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user