fix: a calendar date is the same day everywhere; legal pages use the shared language picker
formatDate read a date-only value as UTC midnight and showed it in the viewer's zone, so the legal pages' last update read a day early west of UTC. Date-only values are shown in UTC. The legal pages' hand-rolled language buttons are the landing page's LanguageSwitcher. formatDateTime and formatDate get the two-language test formatNumber already had.
This commit is contained in:
@@ -176,8 +176,16 @@ export function formatDateTime(iso: string | null | undefined): string {
|
||||
}
|
||||
|
||||
// Absolute day-precision date (e.g. "12 Jan 2017"), shown alongside a relative time. Empty for null.
|
||||
// A DATE-only value ("2026-09-17": a release, the legal pages' last update) is a calendar day, not an
|
||||
// instant: `new Date` reads it as UTC midnight, which is still the day before west of UTC, so it is
|
||||
// shown in UTC. A timestamp is shown in the viewer's own zone, as it should be.
|
||||
export function formatDate(iso: string | null | undefined, lang: string): string {
|
||||
return iso
|
||||
? new Date(iso).toLocaleDateString(lang, { year: "numeric", month: "short", day: "numeric" })
|
||||
: "";
|
||||
if (!iso) return "";
|
||||
const dateOnly = /^\d{4}-\d{2}-\d{2}$/.test(iso);
|
||||
return new Date(iso).toLocaleDateString(lang, {
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
...(dateOnly ? { timeZone: "UTC" } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user