mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
Custom date range selection.
This commit is contained in:
parent
7a8ab94bba
commit
4e103152b2
19 changed files with 545 additions and 40 deletions
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue