type RecurrenceType = 'once a year' | 'twice a year' | 'quarterly' | 'monthly';
function calculateEndDate(startDate: Date, recurrence: RecurrenceType): Date { const endDate = new Date(startDate); // Copy the start date to calculate the end date
switch (recurrence) { case 'once a year': endDate.setFullYear(startDate.getFullYear() + 1); // Add 1 year break; case 'twice a year': endDate.setMonth(startDate.getMonth() + 6); // Add 6 months break; case 'quarterly': endDate.setMonth(startDate.getMonth() + 3); // Add 3 months break; case 'monthly': endDate.setMonth(startDate.getMonth() + 1); // Add 1 month break; default: throw new Error('Invalid recurrence type'); }
return endDate; }