mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
Use dataStartDate for resetDate.
This commit is contained in:
parent
ee8de858d1
commit
0f98fb5959
15 changed files with 172 additions and 85 deletions
38
lib/date.js
38
lib/date.js
|
|
@ -26,7 +26,6 @@ import {
|
|||
differenceInCalendarMonths,
|
||||
differenceInCalendarYears,
|
||||
format,
|
||||
parseISO,
|
||||
} from 'date-fns';
|
||||
import { getDateLocale } from 'lib/lang';
|
||||
|
||||
|
|
@ -43,6 +42,14 @@ export function parseDateRange(value, locale = 'en-US') {
|
|||
return value;
|
||||
}
|
||||
|
||||
if (value === 'all') {
|
||||
return {
|
||||
startDate: new Date(0),
|
||||
endDate: new Date(1),
|
||||
value,
|
||||
};
|
||||
}
|
||||
|
||||
if (value?.startsWith?.('range')) {
|
||||
const [, startAt, endAt] = value.split(':');
|
||||
|
||||
|
|
@ -148,17 +155,32 @@ export function parseDateRange(value, locale = 'en-US') {
|
|||
}
|
||||
}
|
||||
|
||||
export function getDateRangeValues(startDate, endDate) {
|
||||
let unit = 'year';
|
||||
if (differenceInHours(endDate, startDate) <= 48) {
|
||||
unit = 'hour';
|
||||
export function getAllowedUnits(unit) {
|
||||
const units = ['minute', 'hour', 'day', 'month', 'year'];
|
||||
|
||||
return units.splice(units.indexOf(unit));
|
||||
}
|
||||
|
||||
export function getMinimumUnit(startDate, endDate) {
|
||||
if (differenceInMinutes(endDate, startDate) <= 60) {
|
||||
return 'minute';
|
||||
} else if (differenceInHours(endDate, startDate) <= 48) {
|
||||
return 'hour';
|
||||
} else if (differenceInCalendarDays(endDate, startDate) <= 90) {
|
||||
unit = 'day';
|
||||
return 'day';
|
||||
} else if (differenceInCalendarMonths(endDate, startDate) <= 24) {
|
||||
unit = 'month';
|
||||
return 'month';
|
||||
}
|
||||
|
||||
return { startDate: startOfDay(startDate), endDate: endOfDay(endDate), unit };
|
||||
return 'year';
|
||||
}
|
||||
|
||||
export function getDateRangeValues(startDate, endDate) {
|
||||
return {
|
||||
startDate: startOfDay(startDate),
|
||||
endDate: endOfDay(endDate),
|
||||
unit: getMinimumUnit(startDate, endDate),
|
||||
};
|
||||
}
|
||||
|
||||
export function getDateFromString(str) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue