fix(i18n): preserve literal calendar dates in offer comparisons

This commit is contained in:
cesnimda
2026-11-04 01:58:27 +01:00
parent 09904ecc68
commit df0ef68cd9
6 changed files with 52 additions and 10 deletions
@@ -236,3 +236,25 @@ test("uses recorded applied/deadline/contact dates, keeps absent applied dates u
expect(mockedApi.get).toHaveBeenCalledTimes(1);
assertNoWrites();
});
test.each(["America/Los_Angeles", "Europe/Oslo", "Pacific/Kiritimati"].flatMap(timeZone =>
(["en", "nb"] as const).map(language => ({ timeZone, language }))))(
"keeps a literal calendar date while timestamps retain local semantics: $language/$timeZone",
async ({ timeZone, language }) => {
const original = Date.prototype.toLocaleDateString;
jest.spyOn(Date.prototype, "toLocaleDateString").mockImplementation(function (
this: Date, locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions,
) { return original.call(this, locales, { timeZone, ...options }); });
const item = offer(503, { dateApplied: "2026-12-01", deadline: "2026-12-01T00:30:00Z", followUpAt: "2026-12-01T23:30:00-08:00" });
mockedApi.get.mockResolvedValue(paged([item]) as any);
renderPage(language);
const article = await screen.findByRole("article", { name: item.jobTitle });
const fact = (label: string) => within(article).getByText(label).parentElement!;
expect(fact(translations[language].jobTableDateApplied)).toHaveTextContent(language === "nb" ? "1.12.2026" : "12/1/2026");
const formatter = new Intl.DateTimeFormat(language === "nb" ? "nb-NO" : "en", { timeZone });
expect(fact(translations[language].offerComparisonDecisionDeadline)).toHaveTextContent(formatter.format(new Date(item.deadline!)));
expect(fact(translations[language].companiesNextContact)).toHaveTextContent(formatter.format(new Date(item.followUpAt!)));
expect(mockedApi.get).toHaveBeenCalledTimes(1);
assertNoWrites();
},
);
@@ -18,7 +18,7 @@ export default function OfferComparisonPage() {
const retryPending = useRef(false);
const loading = resource.loading || resource.refreshing;
const locale = language === "nb" ? "nb-NO" : "en";
const date = (value?: string | null) => value ? new Date(value).toLocaleDateString(locale) : "—";
const date = (value?: string | null) => value ? new Date(value).toLocaleDateString(locale, /^\d{4}-\d{2}-\d{2}$/.test(value) ? { timeZone: "UTC" } : undefined) : "—";
const periods = new Map([["year", t("salaryPeriodYear")], ["month", t("salaryPeriodMonth")], ["hour", t("salaryPeriodHour")]]);
return (