From 5acb1e3c52df7e8d3ac104efd3e189eb5ea8e835 Mon Sep 17 00:00:00 2001 From: Mariano <132747814+mbelinky@users.noreply.github.com> Date: Mon, 9 Feb 2026 09:04:54 +0100 Subject: [PATCH] Tests: trim timezone in envelope timestamp helper (#12446) --- ...-auto-reply.reconnects-after-connection-close.test.ts | 5 +++++ test/helpers/envelope-timestamp.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) 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; }