wix-style-react
Version:
48 lines (47 loc) • 1.63 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';
var WEEKDAY_SHORT = {
vi: 'iiiii'
};
export default (function (locale, firstDayOfWeek) {
return {
formatMonthTitle: function formatMonthTitle(date) {
return capitalizeMonth(format(date, 'LLLL yyyy', {
locale: locale
}), locale);
},
formatWeekdayShort: function formatWeekdayShort(index) {
var shortWeekdayFormat = WEEKDAY_SHORT[locale] || 'iiiiii';
return format(setDay(new Date(), index), shortWeekdayFormat, {
locale: locale
});
},
formatWeekdayLong: function formatWeekdayLong(index) {
return format(setDay(new Date(), index), 'iiii', {
locale: locale
});
},
formatDay: function formatDay(date) {
return format(date, 'iii PP', {
locale: locale
});
},
getMonths: function getMonths() {
return MONTHS_INDEXES.map(function (i) {
return capitalizeMonth(format(new Date(2018, i), 'LLLL', {
locale: locale
}), locale);
});
},
getFirstDayOfWeek: function getFirstDayOfWeek() {
var _ref;
return (_ref = firstDayOfWeek !== null && firstDayOfWeek !== void 0 ? firstDayOfWeek : FIRST_WEEKDAY[locale]) !== null && _ref !== void 0 ? _ref : 1;
}
};
});