You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

28 lines
723 B

import { NON_INVESTMENT_ACTIVITY_TYPES } from '@ghostfolio/common/config';
import { Type as ActivityType } from '@prisma/client';
import { endOfToday, isAfter } from 'date-fns';
export function isDraftTagToBeAssigned({
date,
endOfTodayDate = endOfToday(),
storedDate,
type
}: {
date: Date;
endOfTodayDate?: Date;
storedDate?: Date;
type: ActivityType;
}) {
if (NON_INVESTMENT_ACTIVITY_TYPES.includes(type)) {
return false;
}
if (!isAfter(date, endOfTodayDate)) {
return false;
}
// Assign only when the date newly moves into the future, so that a tag the
// user has removed is not restored by an unrelated change
return storedDate ? !isAfter(storedDate, endOfTodayDate) : true;
}