Fix frontend locale tests after date-fns changed intl formatting

and also attempt to format dates in locale
This commit is contained in:
Jamie Curnow
2026-01-13 22:42:42 +10:00
parent 9c25410331
commit b01a22c393
8 changed files with 38 additions and 21 deletions

View File

@@ -1,4 +1,9 @@
import { fromUnixTime, intlFormat, parseISO } from "date-fns";
import {
fromUnixTime,
type IntlFormatFormatOptions,
intlFormat,
parseISO,
} from "date-fns";
const isUnixTimestamp = (value: unknown): boolean => {
if (typeof value !== "number" && typeof value !== "string") return false;
@@ -20,20 +25,19 @@ const parseDate = (value: string | number): Date | null => {
}
};
const formatDateTime = (value: string | number): string => {
const formatDateTime = (value: string | number, locale = "en-US"): string => {
const d = parseDate(value);
if (!d) return `${value}`;
try {
return intlFormat(d, {
weekday: "long",
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: true,
});
return intlFormat(
d,
{
dateStyle: "medium",
timeStyle: "medium",
hourCycle: "h12",
} as IntlFormatFormatOptions,
{ locale },
);
} catch {
return `${value}`;
}