Set default date-fns locale

This commit is contained in:
Sam Becker 2025-06-01 12:51:14 -05:00
parent 8a5c874c18
commit d74ee39f11
2 changed files with 8 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import EN_US from './locales/en-us';
import { setDefaultOptions } from 'date-fns';
import { enUS, id, ptBR, pt, zhCN } from 'date-fns/locale';
import { APP_LOCALE } from '@/app/config';
@ -52,4 +53,5 @@ export const getTextForLocale = async (locale: string): Promise<I18N> => {
return text;
};
export const DATE_FN_LOCALE = getDateFnLocale(APP_LOCALE);
export const setDefaultDateFnLocale = () =>
setDefaultOptions({ locale: getDateFnLocale(APP_LOCALE) });

View File

@ -1,7 +1,9 @@
import { parseISO, parse, format } from 'date-fns';
import { formatInTimeZone } from 'date-fns-tz';
import { Timezone } from './timezone';
import { DATE_FN_LOCALE } from '@/i18n';
import { setDefaultDateFnLocale } from '@/i18n';
setDefaultDateFnLocale();
const DATE_STRING_FORMAT_TINY = 'dd MMM yy';
const DATE_STRING_FORMAT_TINY_PLACEHOLDER = '00 000 00';
@ -66,10 +68,8 @@ export const formatDate = ({
return showPlaceholder
? placeholderString
: timezone
? formatInTimeZone(
date, timezone, formatString, { locale: DATE_FN_LOCALE },
)
: format(date, formatString, { locale: DATE_FN_LOCALE });
? formatInTimeZone(date, timezone, formatString)
: format(date, formatString);
};
export const formatDateFromPostgresString = (