Skip to content

Commit 20a7042

Browse files
fix(web): keep timestamp date and time in the same locale (pingdotgg#7081)
Co-authored-by: codex <[email protected]>
1 parent ec141c1 commit 20a7042

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎apps/web/src/timestampFormat.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ describe("formatDayAwareTimestamp", () => {
176176
);
177177
});
178178

179+
it("uses the host locale for both the numeric date and wall-clock time", async () => {
180+
vi.stubGlobal("window", {
181+
desktopBridge: { getSystemLocale: () => "en-GB" },
182+
});
183+
vi.resetModules();
184+
185+
const { formatDayAwareTimestamp: formatWithHostLocale } = await import("./timestampFormat");
186+
const messageAt = iso(2026, 7, 12, 15, 44);
187+
188+
expect(formatWithHostLocale(messageAt, "locale", now)).toBe("12/08 15:44");
189+
190+
vi.unstubAllGlobals();
191+
});
192+
179193
it("returns an empty string for invalid input", () => {
180194
expect(formatDayAwareTimestamp("not-a-date", "12-hour", now)).toBe("");
181195
});

‎apps/web/src/timestampFormat.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ export function formatShortTimestamp(isoDate: string, timestampFormat: Timestamp
127127
return getTimestampFormatter(timestampFormat, false).format(date);
128128
}
129129

130-
const numericDateFormatter = new Intl.DateTimeFormat(undefined, {
130+
const numericDateFormatter = new Intl.DateTimeFormat(timestampLocale, {
131131
month: "numeric",
132132
day: "numeric",
133133
});
134-
const numericDateWithYearFormatter = new Intl.DateTimeFormat(undefined, {
134+
const numericDateWithYearFormatter = new Intl.DateTimeFormat(timestampLocale, {
135135
month: "numeric",
136136
day: "numeric",
137137
year: "numeric",

0 commit comments

Comments
 (0)