Skip to content

Commit 870f8ae

Browse files
committed
fix(usage): say resets momentarily in the final minute
1 parent 50647de commit 870f8ae

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎apps/mobile/src/features/usage/UsageLimitsPooled.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
collectLimitPools,
99
cursorUsageWindowDetails,
1010
displayLimitWindows,
11-
formatDuration,
1211
formatResetsIn,
1312
remainingPercent,
1413
type LimitAccount,
@@ -119,7 +118,9 @@ function PoolWindowCard({
119118
{nextRefill ? (
120119
<Text className="text-xs tabular-nums text-foreground-muted">
121120
↻ +{nextRefill.restoresPercent}%{" "}
122-
{nextRefill.at <= now ? "now" : `in ${formatDuration(nextRefill.at - now)}`}
121+
{formatResetsIn(nextRefill.member.window, now)
122+
?.replace("resets in ", "in ")
123+
.replace("resets now", "now")}
123124
</Text>
124125
) : null}
125126
<View className="flex-row gap-1">

‎packages/shared/src/usageLimits.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ function provider(overrides: Partial<ServerProvider>): ServerProvider {
5656
}
5757

5858
describe("pace", () => {
59+
it.each([
60+
[60_000, "resets in 1m"],
61+
[59_999, "Resets momentarily"],
62+
[1, "Resets momentarily"],
63+
[0, "resets now"],
64+
[-1, "resets now"],
65+
])("formats the reset boundary at %i milliseconds", (remaining, label) => {
66+
expect(
67+
// @effect-diagnostics-next-line globalDate:off
68+
formatResetsIn({ ...window, resetsAt: new Date(now + remaining).toISOString() }, now),
69+
).toBe(label);
70+
});
71+
72+
it("ignores invalid reset timestamps", () => {
73+
expect(formatResetsIn({ ...window, resetsAt: "invalid" }, now)).toBeNull();
74+
});
75+
5976
it("places the clock three fifths through a five-hour window with two hours left", () => {
6077
expect(elapsedShare(window, now)).toBeCloseTo(0.6);
6178
expect(paceOf(window, now)).toBe("under");

‎packages/shared/src/usageLimits.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ export function formatDuration(ms: number): string {
596596
export function formatResetsIn(window: ServerProviderUsageWindow, now: number): string | null {
597597
const resetsAt = resetMillis(window);
598598
if (resetsAt === null) return null;
599-
return resetsAt <= now ? "resets now" : `resets in ${formatDuration(resetsAt - now)}`;
599+
if (resetsAt <= now) return "resets now";
600+
if (resetsAt - now < MINUTE) return "Resets momentarily";
601+
return `resets in ${formatDuration(resetsAt - now)}`;
600602
}
601603

602604
/** Limit commands are served by T3 from the same snapshots as Usage → Limits. */

0 commit comments

Comments
 (0)