feature(lib): locale option for getDateRange

This commit is contained in:
Alexander Klein 2021-03-10 10:20:54 +01:00
parent 17836c70e7
commit eb1029bfc8

View File

@ -36,8 +36,9 @@ export function getLocalTime(t) {
return addMinutes(new Date(t), new Date().getTimezoneOffset());
}
export function getDateRange(value) {
export function getDateRange(value, locale) {
const now = new Date();
const localeOptions = dateLocales[locale];
const { num, unit } = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year)$/).groups;
@ -52,8 +53,8 @@ export function getDateRange(value) {
};
case 'week':
return {
startDate: startOfWeek(now),
endDate: endOfWeek(now),
startDate: startOfWeek(now, { locale: localeOptions }),
endDate: endOfWeek(now, { locale: localeOptions }),
unit: 'day',
value,
};