diff --git a/pm-stack/aggregator/src/alerts.ts b/pm-stack/aggregator/src/alerts.ts index f57454f3cb..a49d87d4e8 100644 --- a/pm-stack/aggregator/src/alerts.ts +++ b/pm-stack/aggregator/src/alerts.ts @@ -91,7 +91,15 @@ export function mergeQuiet(input: unknown): QuietPrefs { const q = input as Record; if (typeof q.start === "string" && /^\d{2}:\d{2}$/.test(q.start)) out.start = q.start; if (typeof q.end === "string" && /^\d{2}:\d{2}$/.test(q.end)) out.end = q.end; - if (typeof q.tz === "string" && q.tz.trim()) out.tz = q.tz.trim(); + if (typeof q.tz === "string" && q.tz.trim()) { + const tz = q.tz.trim(); + try { + new Intl.DateTimeFormat("en-US", { timeZone: tz }); + out.tz = tz; + } catch { + // Keep the default timezone for an invalid stored preference. + } + } if (typeof q.enabled === "boolean") out.enabled = q.enabled; } return out; diff --git a/pm-stack/aggregator/test/alerts.test.ts b/pm-stack/aggregator/test/alerts.test.ts index becf29f70c..ff2a5902b0 100644 --- a/pm-stack/aggregator/test/alerts.test.ts +++ b/pm-stack/aggregator/test/alerts.test.ts @@ -72,6 +72,15 @@ describe("class + quiet merges (design §1/§2)", () => { enabled: true, }); }); + test("invalid quiet timezone falls back to the default", () => { + expect(mergeQuiet({ tz: "Not/AZone" }).tz).toBe("America/Chicago"); + }); + test("valid non-default timezone is preserved and used", () => { + const quiet = mergeQuiet({ tz: "UTC" }); + expect(quiet.tz).toBe("UTC"); + // 2026-01-15T04:00Z is 04:00 UTC (inside), but 22:00 CST (outside). + expect(inQuietHours(quiet, new Date("2026-01-15T04:00:00Z"))).toBe(true); + }); test("inQuietHours wraps midnight and honors the window edges", () => { const q = { start: "23:00", end: "07:00", tz: "America/Chicago" }; // 2026-01-15T05:30Z = Jan 14 23:30 CST — inside.