wix-style-react
Version:
54 lines (44 loc) • 1.25 kB
JavaScript
/**
* This file is used for backward compatibility.
* Since the `locale` prop allow passing `date-fns locale object` as value,
* we still need to support it and to keep this `localeUtils functions` that are based on the date-fns library!
*/
import setDay from 'date-fns/setDay';
import format from 'date-fns/format';
import { MONTHS_INDEXES, FIRST_WEEKDAY, capitalizeMonth } from './LocaleUtils';
const WEEKDAY_SHORT = {
vi: 'iiiii',
};
export default (locale, firstDayOfWeek) => ({
formatMonthTitle: date =>
capitalizeMonth(
format(date, 'LLLL yyyy', {
locale,
}),
locale,
),
formatWeekdayShort: index => {
const shortWeekdayFormat = WEEKDAY_SHORT[locale] || 'iiiiii';
return format(setDay(new Date(), index), shortWeekdayFormat, {
locale,
});
},
formatWeekdayLong: index =>
format(setDay(new Date(), index), 'iiii', {
locale,
}),
formatDay: date =>
format(date, 'iii PP', {
locale,
}),
getMonths: () =>
MONTHS_INDEXES.map(i =>
capitalizeMonth(
format(new Date(2018, i), 'LLLL', {
locale,
}),
locale,
),
),
getFirstDayOfWeek: () => firstDayOfWeek ?? FIRST_WEEKDAY[locale] ?? 1,
});