public static List <DateTime> Dates(this Repeats repeats, DateTime startDate, bool skipFirst = false) { List <DateTime> dates = new List <DateTime>(); switch (repeats) { case Repeats.Monthly: dates.Add(skipFirst ? startDate.AddMonths(1) : startDate); return(dates); case Repeats.Weekly: dates.Add(skipFirst ? startDate.AddDays(_daysInWeek) : startDate); return(dates); case Repeats.Daily: dates.Add(skipFirst ? startDate.AddDays(1) : startDate); return(dates); case Repeats.None: if (!skipFirst) { dates.Add(startDate); } return(dates); default /* DaysOfWeek */: List <DayOfWeek> list = repeats.DaysOfWeek(); for (int i = 0; i < _daysInWeek; i++) { DateTime date = startDate.AddDays(i); if (list.Contains(date.DayOfWeek)) { dates.Add(date); } } if (skipFirst && dates.Count > 0) { dates[0] = dates[0].AddDays(_daysInWeek); } return(dates); } }
public static DateTime ActualDate(this Repeats repeats, DateTime startDate) { switch (repeats) { case Repeats.Monthly: while (startDate.Date < DateTime.Today) { startDate = startDate.AddMonths(1); } return(startDate); case Repeats.Weekly: while (startDate.Date < DateTime.Today) { startDate = startDate.AddDays(_daysInWeek); } return(startDate); case Repeats.Daily: return(DateTime.Today.SetTime(startDate)); case Repeats.None: return(startDate); default /* DaysOfWeek */: if (startDate.Date < DateTime.Today) { startDate = DateTime.Today.SetTime(startDate); } List <DayOfWeek> list = repeats.DaysOfWeek(); for (int i = 0; i < _daysInWeek; i++) { DateTime date = startDate.AddDays(i); if (list.Contains(date.DayOfWeek)) { return(date); } } return(startDate); } }