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> = {
days: 'day',
week: 'weekNumber',
months: 'month',
years: 'year',
hours: 'hour',
@ -117,10 +118,6 @@ function extract(inputDate: Date | DateTime, extraArgs: DatePart[]): number | Da
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);
}