private static DateTime?GetStartDateForWeek(DateTime today, RecurringGift gift) { var todayDay = (int)today.DayOfWeek; var giftDay = (int)gift.DayOfWeek; var days = todayDay == giftDay ? 7 : (giftDay - todayDay + 7) % 7; return(today.AddDays(days)); }
private static DateTime?GetStartForMonth(DateTime today, RecurringGift gift) { var giftDay = gift.Day_Of_Month.Value; var months = today.Day < giftDay ? 0 : 1; var updatedGiftMonth = today.AddMonths(months); if (giftDay > DateTime.DaysInMonth(updatedGiftMonth.Year, updatedGiftMonth.Month)) { // Can't update this gift, because the day of the gift isn't in the month of the gift, we'll try again next month return(null); } var giftDate = new DateTime(today.Year, today.Month, giftDay); return(giftDate.AddMonths(months)); }
private static DateTime?CalculateTrialEndDate(RecurringGift gift) { var today = DateTime.Today; return(gift.Frequency_ID == 1 ? GetStartDateForWeek(today, gift) : GetStartForMonth(today, gift)); }