Cleaned up language files.

This commit is contained in:
Mike Cao 2021-11-04 17:09:03 -07:00
parent 33b87b41a9
commit 92b205b7b7
6 changed files with 50 additions and 94 deletions

View file

@ -26,7 +26,7 @@ import {
format,
} from 'date-fns';
import { enUS } from 'date-fns/locale';
import { dateLocales } from 'lib/lang';
import { languages } from 'lib/lang';
export function getTimezone() {
return moment.tz.guess();
@ -38,7 +38,7 @@ export function getLocalTime(t) {
export function getDateRange(value, locale = 'en-US') {
const now = new Date();
const localeOptions = dateLocales[locale];
const dateLocale = languages[locale]?.dateLocale || enUS;
const { num, unit } = value.match(/^(?<num>[0-9]+)(?<unit>hour|day|week|month|year)$/).groups;
@ -53,8 +53,8 @@ export function getDateRange(value, locale = 'en-US') {
};
case 'week':
return {
startDate: startOfWeek(now, { locale: localeOptions }),
endDate: endOfWeek(now, { locale: localeOptions }),
startDate: startOfWeek(now, { locale: dateLocale }),
endDate: endOfWeek(now, { locale: dateLocale }),
unit: 'day',
value,
};
@ -164,6 +164,6 @@ export const customFormats = {
export function dateFormat(date, str, locale = 'en-US') {
return format(date, customFormats?.[locale]?.[str] || str, {
locale: dateLocales[locale] || enUS,
locale: languages[locale]?.dateLocale || enUS,
});
}