Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pm-stack/aggregator/src/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ export function mergeQuiet(input: unknown): QuietPrefs {
const q = input as Record<string, unknown>;
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;
Expand Down
9 changes: 9 additions & 0 deletions pm-stack/aggregator/test/alerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading