mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-17 03:19:59 +03:00
5f114c26d6
Issue: https://github.com/StanGirard/quivr/issues/1865 Demo: https://github.com/StanGirard/quivr/assets/63923024/e7a2fec9-0eac-4f92-9e99-a0bf3cec8e73
32 lines
793 B
TypeScript
32 lines
793 B
TypeScript
export const isToday = (date: Date): boolean => {
|
|
const today = new Date();
|
|
|
|
return date.toDateString() === today.toDateString();
|
|
};
|
|
|
|
export const isYesterday = (date: Date): boolean => {
|
|
const yesterday = new Date();
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
|
|
return date.toDateString() === yesterday.toDateString();
|
|
};
|
|
|
|
export const isWithinLast7Days = (date: Date): boolean => {
|
|
const weekAgo = new Date();
|
|
weekAgo.setDate(weekAgo.getDate() - 7);
|
|
|
|
return date > weekAgo && !isToday(date) && !isYesterday(date);
|
|
};
|
|
|
|
export const isWithinLast30Days = (date: Date): boolean => {
|
|
const monthAgo = new Date();
|
|
monthAgo.setDate(monthAgo.getDate() - 30);
|
|
|
|
return (
|
|
date > monthAgo &&
|
|
!isToday(date) &&
|
|
!isYesterday(date) &&
|
|
!isWithinLast7Days(date)
|
|
);
|
|
};
|