Progress check-in for date compare.

This commit is contained in:
Mike Cao 2024-05-23 19:35:29 -07:00
parent 24af06f3aa
commit 8cf7985dac
25 changed files with 181 additions and 61 deletions

View file

@ -20,6 +20,7 @@ export const DEFAULT_DATE_RANGE = '24hour';
export const DEFAULT_WEBSITE_LIMIT = 10;
export const DEFAULT_RESET_DATE = '2000-01-01';
export const DEFAULT_PAGE_SIZE = 10;
export const DEFAULT_DATE_COMPARE = 'prev';
export const REALTIME_RANGE = 30;
export const REALTIME_INTERVAL = 5000;

View file

@ -326,3 +326,13 @@ export function getDateLength(startDate: Date, endDate: Date, unit: string | num
const { diff } = DATE_FUNCTIONS[unit];
return diff(endDate, startDate) + 1;
}
export function getCompareDate(compare: string, startDate: Date, endDate: Date) {
if (compare === 'yoy') {
return { startDate: subYears(startDate, 1), endDate: subYears(endDate, 1) };
}
const diff = differenceInMinutes(endDate, startDate);
return { startDate: subMinutes(startDate, diff), endDate: subMinutes(endDate, diff) };
}