mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 14:47:14 +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) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import cache from 'lib/cache';
|
||||
import { getWebsite, getSession, getUser } from 'queries';
|
||||
import { User, Website, Session } from '@prisma/client';
|
||||
import { DEFAULT_RESET_DATE } from './constants';
|
||||
|
||||
export async function loadWebsite(websiteId: string): Promise<Website> {
|
||||
export async function loadWebsite(websiteId: string): Promise<Website & { dataStartDate: Date }> {
|
||||
let website;
|
||||
|
||||
if (cache.enabled) {
|
||||
|
|
@ -11,6 +12,8 @@ export async function loadWebsite(websiteId: string): Promise<Website> {
|
|||
website = await getWebsite({ id: websiteId });
|
||||
}
|
||||
|
||||
website.dataStartDate = new Date(website?.resetAt || DEFAULT_RESET_DATE);
|
||||
|
||||
if (!website || website.deletedAt) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue