Custom date range selection.

This commit is contained in:
Mike Cao 2020-09-13 01:26:54 -07:00
parent 7a8ab94bba
commit 4e103152b2
19 changed files with 545 additions and 40 deletions

View file

@ -18,7 +18,7 @@ import {
endOfYear,
differenceInHours,
differenceInCalendarDays,
differenceInMonths,
differenceInCalendarMonths,
} from 'date-fns';
export function getTimezone() {
@ -85,10 +85,21 @@ export function getDateRange(value) {
}
}
export function getDateRangeValues(startDate, endDate) {
if (differenceInHours(endDate, startDate) <= 48) {
return { startDate: startOfHour(startDate), endDate: endOfHour(endDate), unit: 'hour' };
} else if (differenceInCalendarDays(endDate, startDate) <= 90) {
return { startDate: startOfDay(startDate), endDate: endOfDay(endDate), unit: 'day' };
} else if (differenceInCalendarMonths(endDate, startDate) <= 12) {
return { startDate: startOfMonth(startDate), endDate: endOfMonth(endDate), unit: 'month' };
}
return { startDate: startOfYear(startDate), endDate: endOfYear(endDate), unit: 'year' };
}
const dateFuncs = {
hour: [differenceInHours, addHours, startOfHour],
day: [differenceInCalendarDays, addDays, startOfDay],
month: [differenceInMonths, addMonths, startOfMonth],
month: [differenceInCalendarMonths, addMonths, startOfMonth],
};
export function getDateArray(data, startDate, endDate, unit) {