Use DATETIMEUNIT_MAP

This commit is contained in:
Iván Ovejero 2023-01-23 12:04:43 +01:00
parent 7bfb00f502
commit 472a77df5c

View file

@ -53,6 +53,7 @@ const DURATION_MAP: Record<string, DurationUnit> = {
const DATETIMEUNIT_MAP: Record<string, DateTimeUnit> = { const DATETIMEUNIT_MAP: Record<string, DateTimeUnit> = {
days: 'day', days: 'day',
week: 'weekNumber',
months: 'month', months: 'month',
years: 'year', years: 'year',
hours: 'hour', hours: 'hour',
@ -117,10 +118,6 @@ function extract(inputDate: Date | DateTime, extraArgs: DatePart[]): number | Da
return Math.floor(diff / (1000 * 60 * 60 * 24)); return Math.floor(diff / (1000 * 60 * 60 * 24));
} }
if (part === 'week') {
part = 'weekNumber';
}
return DateTime.fromJSDate(date).get((DATETIMEUNIT_MAP[part] as keyof DateTime) || part); return DateTime.fromJSDate(date).get((DATETIMEUNIT_MAP[part] as keyof DateTime) || part);
} }