Custom date range selection.
This commit is contained in:
15
lib/date.js
15
lib/date.js
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user