From 528ecfbcdc5788bed093a50bc8b8f23773aef9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 4 Oct 2026 19:07:54 +0200 Subject: [PATCH] test(tz): reuse one reference formatter per zone in the offset parity test The parity test built a fresh Intl.DateTimeFormat for each of ~36k comparisons and crossed the 5 s timeout on CI runners. One formatter per zone halves its time; it also gets an explicit 20 s budget, since it is meant to be exhaustive. --- src/lib/tz/__tests__/zone-offset.test.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib/tz/__tests__/zone-offset.test.ts b/src/lib/tz/__tests__/zone-offset.test.ts index 6c411738f..26e558cb2 100644 --- a/src/lib/tz/__tests__/zone-offset.test.ts +++ b/src/lib/tz/__tests__/zone-offset.test.ts @@ -34,11 +34,20 @@ const REFERENCE_OPTIONS: Intl.DateTimeFormatOptions = { }; const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; +// One reference formatter per zone: building a fresh Intl.DateTimeFormat for +// each of ~36k comparisons pushed the test past its timeout on CI runners. +const referenceFormatters = new Map(); + function reference(date: Date, tz: string) { - const parts = new Intl.DateTimeFormat("en-US", { - ...REFERENCE_OPTIONS, - timeZone: tz, - }).formatToParts(date); + let fmt = referenceFormatters.get(tz); + if (!fmt) { + fmt = new Intl.DateTimeFormat("en-US", { + ...REFERENCE_OPTIONS, + timeZone: tz, + }); + referenceFormatters.set(tz, fmt); + } + const parts = fmt.formatToParts(date); const get = (type: string) => parts.find((p) => p.type === type)!.value; const hour = Number(get("hour")) % 24; const wall = { @@ -103,7 +112,7 @@ describe("zone offset memo", () => { expect(formatInUserTz(date, tz, "datetime")).toBe(ref.datetime); } } - }); + }, 20_000); it("matches Intl on a warm memo for scattered instants across decades", () => { let seed = 7;