@devries-cameron20 / t3code Mirror · read-only / commits / 689bdb82e9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 05:45 UTC

fix(web): usage-limit retry notice shows the timezone (#23029)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 2, 2026 at 18:52 UTC 689bdb82e95e6ebc2c23ae5222422a1941cdcf9f
5 files changed +163 -35
apps/mobile/src/features/threads/thread-work-log.tsx
+3 -2
@@ -937,13 +937,14 @@ const ThreadWorkLogRow = function ThreadWorkLogRow(
937 const warning = failureItem.failure.class === "usage_limit";
938 const timestamp = new Date(row.createdAt);
939 const resetAt = failureItem.failure.resetAt;
940 + // The reset time is the viewer's local time; naming the zone keeps it unambiguous.
941 const resetTime = resetAt
941 - ? new Date(resetAt).toLocaleString(undefined, {
942 + ? `${new Date(resetAt).toLocaleString(undefined, {
943 month: "short",
944 day: "numeric",
945 hour: "numeric",
946 minute: "2-digit",
946 - })
947 + })} (${new Intl.DateTimeFormat().resolvedOptions().timeZone})`
948 : null;
949 const label = warning
950 ? `Usage limit reached.${resetTime ? ` Retry after ${resetTime}.` : ""}`
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+71 -1
@@ -1,6 +1,6 @@
1 import { flushSync } from "react-dom";
2 import { AudioPreview } from "../files/AudioPreview";
3 -import { page } from "vite-plus/test/browser";
3 +import { cdp, page } from "vite-plus/test/browser";
4 import {
5 ComposerContextId,
6 EnvironmentId,
@@ -565,6 +565,76 @@ describe("MessagesTimeline messages", () => {
565 });
566 });
567
568 +function usageLimitEntries(resetAt: string) {
569 + const threadId = ThreadId.make("usage-limit-thread");
570 + const at = DateTime.makeUnsafe(CREATED_AT);
571 + return deriveTimelineEntriesFromVisibleTurnItems({
572 + visibleTurnItems: [
573 + {
574 + position: 0,
575 + visibility: "local",
576 + sourceThreadId: threadId,
577 + sourceItemId: TurnItemId.make("usage-limit"),
578 + item: {
579 + id: TurnItemId.make("usage-limit"),
580 + threadId,
581 + runId: RunId.make("usage-limit-run"),
582 + nodeId: null,
583 + providerThreadId: null,
584 + providerTurnId: null,
585 + nativeItemRef: null,
586 + parentItemId: null,
587 + ordinal: 0,
588 + title: null,
589 + startedAt: at,
590 + completedAt: at,
591 + updatedAt: at,
592 + type: "error",
593 + status: "failed",
594 + failure: {
595 + class: "usage_limit",
596 + message: "You've hit your usage limit.",
597 + code: null,
598 + retryable: true,
599 + resetAt,
600 + },
601 + },
602 + },
603 + ],
604 + optimisticMessages: [],
605 + });
606 +}
607 +
608 +describe("MessagesTimeline usage limit notice", () => {
609 + it("labels the retry time with the viewer's timezone", async () => {
610 + await using screen = await renderTimeline(usageLimitEntries("2026-03-17T19:30:00.000Z"));
611 + const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
612 + expect(screen.text()).toMatch(/Usage limit reached\. Retry after .+\./);
613 + expect(screen.text()).toContain(`(${timeZone})`);
614 + });
615 +
616 + it("keeps the retry time in the named zone after the viewer's timezone changes", async () => {
617 + const resetAt = "2026-07-01T19:30:00.000Z";
618 + const session = cdp();
619 + await session.send("Emulation.setTimezoneOverride", { timezoneId: "Europe/Madrid" });
620 + try {
621 + {
622 + await using _madrid = await renderTimeline(usageLimitEntries(resetAt));
623 + }
624 + await session.send("Emulation.setTimezoneOverride", { timezoneId: "America/New_York" });
625 + await using screen = await renderTimeline(usageLimitEntries(resetAt));
626 + const newYorkTime = new Date(resetAt).toLocaleTimeString(undefined, {
627 + hour: "numeric",
628 + minute: "2-digit",
629 + timeZone: "America/New_York",
630 + });
631 + expect(screen.text()).toContain(`${newYorkTime} (America/New_York)`);
632 + } finally {
633 + await session.send("Emulation.setTimezoneOverride", { timezoneId: "" });
634 + }
635 + });
636 +});
637 +
638 const CITATION_REQUEST = {
639 key: "activation-1",
640 citation: {
apps/web/src/components/chat/TimelineWorkEntryRow.tsx
+6 -1
@@ -209,7 +209,12 @@ function WorkEntryLogRow(props: WorkEntryRowProps) {
209 if (failureItem?.type === "error" && failureItem.status === "failed") {
210 const warning = failureItem.failure.class === "usage_limit";
211 const resetAt = failureItem.failure.resetAt;
212 - const resetTime = resetAt ? formatUpcomingTimestamp(resetAt, timestampFormat) : null;
212 + // The reset time is the viewer's local time; naming the zone keeps it
213 + // unambiguous. Both read the zone now, since the device's can change.
214 + const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
215 + const resetTime = resetAt
216 + ? `${formatUpcomingTimestamp(resetAt, timestampFormat, undefined, timeZone)} (${timeZone})`
217 + : null;
218 const label = warning
219 ? `Usage limit reached.${resetTime ? ` Retry after ${resetTime}.` : ""}`
220 : workEntry.label;
apps/web/src/timestampFormat.test.ts new
+21
@@ -0,0 +1,21 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { formatDayAwareTimestamp, formatUpcomingTimestamp } from "./timestampFormat";
4 +
5 +describe("timestamps in an explicit time zone", () => {
6 + // 23:00 UTC on July 1 is 7 PM on July 1 in New York, whatever the host zone.
7 + const now = Date.parse("2026-07-01T23:00:00.000Z");
8 + const zone = "America/New_York";
9 +
10 + it("picks relative days from the calendar in that zone", () => {
11 + expect(formatUpcomingTimestamp("2026-07-02T00:30:00.000Z", "12-hour", now, zone)).not.toMatch(
12 + /tomorrow/,
13 + );
14 + expect(formatUpcomingTimestamp("2026-07-02T05:30:00.000Z", "12-hour", now, zone)).toMatch(
15 + /^tomorrow at /,
16 + );
17 + expect(formatDayAwareTimestamp("2026-07-01T03:30:00.000Z", "12-hour", now, zone)).toMatch(
18 + /^yesterday at /,
19 + );
20 + });
21 +});
apps/web/src/timestampFormat.ts
+62 -31
@@ -73,17 +73,18 @@ const timestampFormatterCache = new Map<string, Intl.DateTimeFormat>();
73 function getTimestampFormatter(
74 timestampFormat: TimestampFormat,
75 includeSeconds: boolean,
76 + timeZone?: string,
77 ): Intl.DateTimeFormat {
77 - const cacheKey = `${timestampFormat}:${includeSeconds ? "seconds" : "minutes"}`;
78 + const cacheKey = `${timestampFormat}:${includeSeconds ? "seconds" : "minutes"}:${timeZone ?? ""}`;
79 const cachedFormatter = timestampFormatterCache.get(cacheKey);
80 if (cachedFormatter) {
81 return cachedFormatter;
82 }
83
83 - const formatter = new Intl.DateTimeFormat(
84 - timestampLocale,
85 - getTimestampFormatOptions(timestampFormat, includeSeconds),
86 - );
84 + const formatter = new Intl.DateTimeFormat(timestampLocale, {
85 + ...getTimestampFormatOptions(timestampFormat, includeSeconds),
86 + ...(timeZone ? { timeZone } : {}),
87 + });
88 timestampFormatterCache.set(cacheKey, formatter);
89 return formatter;
90 }
@@ -136,58 +137,88 @@ export function formatShortTimestamp(isoDate: string, timestampFormat: Timestamp
137 return getTimestampFormatter(timestampFormat, false).format(date);
138 }
139
139 -const numericDateFormatter = new Intl.DateTimeFormat(timestampLocale, {
140 - month: "numeric",
141 - day: "numeric",
142 -});
143 -const numericDateWithYearFormatter = new Intl.DateTimeFormat(timestampLocale, {
144 - month: "numeric",
145 - day: "numeric",
140 +const numericDateOptions: Intl.DateTimeFormatOptions = { month: "numeric", day: "numeric" };
141 +const numericDateWithYearOptions: Intl.DateTimeFormatOptions = {
142 + ...numericDateOptions,
143 year: "numeric",
147 -});
144 +};
145 +const numericDateFormatter = new Intl.DateTimeFormat(timestampLocale, numericDateOptions);
146 +const numericDateWithYearFormatter = new Intl.DateTimeFormat(
147 + timestampLocale,
148 + numericDateWithYearOptions,
149 +);
150 +
151 +interface CalendarDay {
152 + year: number;
153 + /** Days since the epoch, so differences are whole days across DST shifts. */
154 + index: number;
155 +}
156 +
157 +function calendarDay(date: Date, timeZone: string | undefined): CalendarDay {
158 + if (!timeZone) {
159 + const year = date.getFullYear();
160 + return { year, index: Date.UTC(year, date.getMonth(), date.getDate()) / 86_400_000 };
161 + }
162 + const parts = new Intl.DateTimeFormat("en-US", {
163 + timeZone,
164 + year: "numeric",
165 + month: "numeric",
166 + day: "numeric",
167 + }).formatToParts(date);
168 + const part = (type: Intl.DateTimeFormatPartTypes) =>
169 + Number(parts.find((entry) => entry.type === type)?.value);
170 + const year = part("year");
171 + return { year, index: Date.UTC(year, part("month") - 1, part("day")) / 86_400_000 };
172 +}
173 +
174 +function formatNumericDate(date: Date, sameYear: boolean, timeZone: string | undefined): string {
175 + if (!timeZone) {
176 + return (sameYear ? numericDateFormatter : numericDateWithYearFormatter).format(date);
177 + }
178 + return new Intl.DateTimeFormat(timestampLocale, {
179 + ...(sameYear ? numericDateOptions : numericDateWithYearOptions),
180 + timeZone,
181 + }).format(date);
182 +}
183
184 export function formatDayAwareTimestamp(
185 isoDate: string,
186 timestampFormat: TimestampFormat,
187 nowMs: number = Date.now(),
188 + timeZone?: string,
189 ): string {
190 const date = parseTimestampDate(isoDate);
191 if (!date) return "";
156 - const time = getTimestampFormatter(timestampFormat, false).format(date);
192 + const time = getTimestampFormatter(timestampFormat, false, timeZone).format(date);
193
158 - const now = new Date(nowMs);
159 - const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
160 - const startOfMessageDay = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
161 - // Round so DST-shifted 23/25 hour days still count as whole days.
162 - const dayDiff = Math.round((startOfToday - startOfMessageDay) / 86_400_000);
194 + const today = calendarDay(new Date(nowMs), timeZone);
195 + const messageDay = calendarDay(date, timeZone);
196 + const dayDiff = today.index - messageDay.index;
197
198 if (dayDiff <= 0) return time;
199 if (dayDiff === 1) return `yesterday at ${time}`;
166 - const dateFormatter =
167 - date.getFullYear() === now.getFullYear() ? numericDateFormatter : numericDateWithYearFormatter;
168 - return `${dateFormatter.format(date)} ${time}`;
200 + return `${formatNumericDate(date, messageDay.year === today.year, timeZone)} ${time}`;
201 }
202
203 +/** `timeZone` overrides the zone the formatters cached when they were built. */
204 export function formatUpcomingTimestamp(
205 isoDate: string,
206 timestampFormat: TimestampFormat,
207 nowMs: number = Date.now(),
208 + timeZone?: string,
209 ): string {
210 const date = parseTimestampDate(isoDate);
211 if (!date) return "";
178 - const time = getTimestampFormatter(timestampFormat, false).format(date);
212 + const time = getTimestampFormatter(timestampFormat, false, timeZone).format(date);
213
180 - const now = new Date(nowMs);
181 - const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
182 - const startOfTargetDay = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
183 - const dayDiff = Math.round((startOfTargetDay - startOfToday) / 86_400_000);
214 + const today = calendarDay(new Date(nowMs), timeZone);
215 + const targetDay = calendarDay(date, timeZone);
216 + const dayDiff = targetDay.index - today.index;
217
185 - if (dayDiff < 0) return formatDayAwareTimestamp(isoDate, timestampFormat, nowMs);
218 + if (dayDiff < 0) return formatDayAwareTimestamp(isoDate, timestampFormat, nowMs, timeZone);
219 if (dayDiff === 0) return time;
220 if (dayDiff === 1) return `tomorrow at ${time}`;
188 - const dateFormatter =
189 - date.getFullYear() === now.getFullYear() ? numericDateFormatter : numericDateWithYearFormatter;
190 - return `${dateFormatter.format(date)} ${time}`;
221 + return `${formatNumericDate(date, targetDay.year === today.year, timeZone)} ${time}`;
222 }
223
224 type RelativeTimeParts = { value: string; suffix: string | null };