diff --git a/src/web/auto-reply.web-auto-reply.reconnects-after-connection-close.test.ts b/src/web/auto-reply.web-auto-reply.reconnects-after-connection-close.test.ts index 9c6bcd37ef6..c096253729e 100644 --- a/src/web/auto-reply.web-auto-reply.reconnects-after-connection-close.test.ts +++ b/src/web/auto-reply.web-auto-reply.reconnects-after-connection-close.test.ts @@ -106,6 +106,11 @@ describe("web auto-reply", () => { vi.useRealTimers(); }); + it("handles helper envelope timestamps with trimmed timezones (regression)", () => { + const d = new Date("2025-01-01T00:00:00.000Z"); + expect(() => formatEnvelopeTimestamp(d, " America/Los_Angeles ")).not.toThrow(); + }); + it("reconnects after a connection close", async () => { const closeResolvers: Array<() => void> = []; const sleep = vi.fn(async () => {}); diff --git a/test/helpers/envelope-timestamp.ts b/test/helpers/envelope-timestamp.ts index f86c90d7660..70c6bbe58c2 100644 --- a/test/helpers/envelope-timestamp.ts +++ b/test/helpers/envelope-timestamp.ts @@ -8,7 +8,8 @@ export { escapeRegExp } from "../../src/utils.js"; type EnvelopeTimestampZone = string; export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone = "utc"): string { - const normalized = zone.trim().toLowerCase(); + const trimmedZone = zone.trim(); + const normalized = trimmedZone.toLowerCase(); const weekday = (() => { try { if (normalized === "utc" || normalized === "gmt") { @@ -17,7 +18,9 @@ export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone if (normalized === "local" || normalized === "host") { return new Intl.DateTimeFormat("en-US", { weekday: "short" }).format(date); } - return new Intl.DateTimeFormat("en-US", { timeZone: zone, weekday: "short" }).format(date); + return new Intl.DateTimeFormat("en-US", { timeZone: trimmedZone, weekday: "short" }).format( + date, + ); } catch { return undefined; } @@ -31,7 +34,7 @@ export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone const ts = formatZonedTimestamp(date) ?? formatUtcTimestamp(date); return weekday ? `${weekday} ${ts}` : ts; } - const ts = formatZonedTimestamp(date, { timeZone: zone }) ?? formatUtcTimestamp(date); + const ts = formatZonedTimestamp(date, { timeZone: trimmedZone }) ?? formatUtcTimestamp(date); return weekday ? `${weekday} ${ts}` : ts; }