fix(usage): say resets momentarily in the final minute (#17869)
This commit is contained in:
1 parent
ed0f7b908b
commit
2625327090
3 files changed
+20
-3
No files matched your search
@@ -8,7 +8,6 @@ import {
|
||||
collectLimitPools,
|
||||
cursorUsageWindowDetails,
|
||||
displayLimitWindows,
|
||||
formatDuration,
|
||||
formatResetsIn,
|
||||
remainingPercent,
|
||||
type LimitAccount,
|
||||
@@ -123,7 +122,9 @@ function PoolWindowCard({
|
||||
{nextRefill ? (
|
||||
<Text className="text-xs tabular-nums text-foreground-muted">
|
||||
↻ +{nextRefill.restoresPercent}%{" "}
|
||||
{nextRefill.at <= now ? "now" : `in ${formatDuration(nextRefill.at - now)}`}
|
||||
{formatResetsIn(nextRefill.member.window, now)
|
||||
?.replace("resets in ", "in ")
|
||||
.replace("resets now", "now")}
|
||||
</Text>
|
||||
) : null}
|
||||
<View className="flex-row gap-1">
|
||||
|
||||
@@ -56,6 +56,20 @@ function provider(overrides: Partial<ServerProvider>): ServerProvider {
|
||||
}
|
||||
|
||||
describe("pace", () => {
|
||||
it.each([
|
||||
["2026-09-03T12:01:00.000Z", "resets in 1m"],
|
||||
["2026-09-03T12:00:59.999Z", "Resets momentarily"],
|
||||
["2026-09-03T12:00:00.001Z", "Resets momentarily"],
|
||||
["2026-09-03T12:00:00.000Z", "resets now"],
|
||||
["2026-09-03T11:59:59.999Z", "resets now"],
|
||||
])("formats the reset boundary at %s", (resetsAt, label) => {
|
||||
expect(formatResetsIn({ ...window, resetsAt }, now)).toBe(label);
|
||||
});
|
||||
|
||||
it("ignores invalid reset timestamps", () => {
|
||||
expect(formatResetsIn({ ...window, resetsAt: "invalid" }, now)).toBeNull();
|
||||
});
|
||||
|
||||
it("places the clock three fifths through a five-hour window with two hours left", () => {
|
||||
expect(elapsedShare(window, now)).toBeCloseTo(0.6);
|
||||
expect(paceOf(window, now)).toBe("under");
|
||||
|
||||
@@ -607,7 +607,9 @@ export function formatDuration(ms: number): string {
|
||||
export function formatResetsIn(window: ServerProviderUsageWindow, now: number): string | null {
|
||||
const resetsAt = resetMillis(window);
|
||||
if (resetsAt === null) return null;
|
||||
return resetsAt <= now ? "resets now" : `resets in ${formatDuration(resetsAt - now)}`;
|
||||
if (resetsAt <= now) return "resets now";
|
||||
if (resetsAt - now < MINUTE) return "Resets momentarily";
|
||||
return `resets in ${formatDuration(resetsAt - now)}`;
|
||||
}
|
||||
|
||||
/** Limit commands are served by T3 from the same snapshots as Usage → Limits. */
|
||||
|
||||
Reference in new issue
Block a user