plane/space/helpers/issue.helper.ts

31 lines
952 B
TypeScript
Raw Normal View History

import { differenceInCalendarDays } from "date-fns";
// types
import { TStateGroups } from "@plane/types";
// constants
import { STATE_GROUPS } from "@/constants/state";
// helpers
import { getDate } from "@/helpers/date-time.helper";
/**
* @description check if the issue due date should be highlighted
* @param date
* @param stateGroup
* @returns boolean
*/
export const shouldHighlightIssueDueDate = (
date: string | Date | null,
stateGroup: TStateGroups | undefined
): boolean => {
if (!date || !stateGroup) return false;
// if the issue is completed or cancelled, don't highlight the due date
if ([STATE_GROUPS.completed.key, STATE_GROUPS.cancelled.key].includes(stateGroup)) return false;
const parsedDate = getDate(date);
if (!parsedDate) return false;
const targetDateDistance = differenceInCalendarDays(parsedDate, new Date());
// if the issue is overdue, highlight the due date
return targetDateDistance <= 0;
};