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,5 +1,6 @@
import cn from "classnames";
import { differenceInDays, isPast } from "date-fns";
import { useLocaleState } from "src/context";
import { formatDateTime, parseDate } from "src/locale";
interface Props {
@@ -8,6 +9,7 @@ interface Props {
highlistNearlyExpired?: boolean;
}
export function DateFormatter({ value, highlightPast, highlistNearlyExpired }: Props) {
const { locale } = useLocaleState();
const d = parseDate(value);
const dateIsPast = d ? isPast(d) : false;
const days = d ? differenceInDays(d, new Date()) : 0;
@@ -15,5 +17,5 @@ export function DateFormatter({ value, highlightPast, highlistNearlyExpired }: P
"text-danger": highlightPast && dateIsPast,
"text-warning": highlistNearlyExpired && !dateIsPast && days <= 30 && days >= 0,
});
return <span className={cl}>{formatDateTime(value)}</span>;
return <span className={cl}>{formatDateTime(value, locale)}</span>;
}