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
11
lib/array.js
Normal file
11
lib/array.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export function chunk(arr, size) {
|
||||
const chunks = [];
|
||||
|
||||
let index = 0;
|
||||
while (index < arr.length) {
|
||||
chunks.push(arr.slice(index, size + index));
|
||||
index += size;
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import deDEMessages from 'lang-compiled/de-DE.json';
|
|||
import jaMessages from 'lang-compiled/ja-JP.json';
|
||||
|
||||
export const messages = {
|
||||
en: enMessages,
|
||||
'en-US': enMessages,
|
||||
'nl-NL': nlMessages,
|
||||
'zh-CN': zhCNMessages,
|
||||
'de-DE': deDEMessages,
|
||||
|
|
@ -19,7 +19,7 @@ export const messages = {
|
|||
};
|
||||
|
||||
export const dateLocales = {
|
||||
en: enUS,
|
||||
'en-US': enUS,
|
||||
'nl-NL': nl,
|
||||
'zh-CN': zhCN,
|
||||
'de-DE': de,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue