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

@ -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) };
}