1 import { localeCode } from '../i18n';
2 import { getIntlLocale } from '../i18n/helper';
5 * Format date with Intl.DateTimeFormat
6 * @param date date to be formatted
7 * @param options formatting options, e.g. { weekday: 'short', month: 'long', year: 'numeric', timeStyle: 'short' }
8 * @param locale [Optional] locale to be used when formatting. Defaults to the app locale
10 export const formatIntlDate = (date: Date, options: Intl.DateTimeFormatOptions, locale = localeCode) => {
11 const intlLocale = getIntlLocale(locale);
12 // In case the locale is not recognized by Intl, we fallback to en-US
13 const formatter = new Intl.DateTimeFormat([intlLocale, 'en-US'], options);
15 return formatter.format(date);