test(i18n): cover month labels when Intl defaults to UTC like the native polyfill

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jakeandClaude Sonnet 5.5 committed 2026-10-05 13:48:29 -04:00
1 parent c40b6844a0
commit 1ccc138144
1 file changed
+20
+20
View File
@@ -100,6 +100,26 @@ describe("groupByDateBucket", () => {
}
});
test("month label is right when Intl defaults to UTC (native polyfill)", () => {
const RealDTF = Intl.DateTimeFormat;
const originalTz = process.env.TZ;
try {
process.env.TZ = "Pacific/Kiritimati"; // UTC+14
// Emulate the polyfill's UTC default while still honouring an explicit timeZone.
vi.spyOn(Intl, "DateTimeFormat").mockImplementation(function (
locales?: Intl.LocalesArgument,
options?: Intl.DateTimeFormatOptions,
) {
return new RealDTF(locales, { timeZone: "UTC", ...options });
} as unknown as typeof Intl.DateTimeFormat);
expect(groupByDateBucket([{ date: "2024-12-03" }])[0].label).toBe("December");
} finally {
vi.restoreAllMocks();
if (originalTz === undefined) delete process.env.TZ;
else process.env.TZ = originalTz;
}
});
test("item 30+ days out goes to month bucket", () => {
const result = groupByDateBucket([{ date: "2024-08-15" }]);
expect(result).toHaveLength(1);