ScheduleHelperGetValidDaysByOccurrence Method |
Namespace: Xcalibur.Helpers
public static DateTime[] GetValidDaysByOccurrence( DateTime startDate, int numberOfDays, int numberOfOccurrences = 1, int maximumYearsAllowed = 1 )
1static void Main(string[] args) 2{ 3 var startDate = new DateTime(2018, 2, 17); 4 var endDate = startDate.AddMonths(4); 5 6 // Occurs every 10 days up to the end date 7 Console.WriteLine("By date range:"); 8 var dates = ScheduleHelper.GetValidDaysBySchedule(startDate, endDate, 10); 9 foreach (var date in dates) 10 { 11 Console.WriteLine($"{date:MM/dd/yyyy, dddd}"); 12 } 13 14 // Spacer 15 Console.WriteLine(""); 16 17 // Occurs every 10 days, up to 10 times, not to exceed 1 year 18 Console.WriteLine("By # of occurrences:"); 19 var dates2 = ScheduleHelper.GetValidDaysByOccurrence(startDate, 10, 10, 1); 20 foreach (var date in dates2) 21 { 22 Console.WriteLine($"{date:MM/dd/yyyy, dddd}"); 23 } 24 25 // Hold 26 Console.Read(); 27} 28 29/* Result: 30 * 31 * By date range: 32 * 02/17/2018, Saturday 33 * 02/27/2018, Tuesday 34 * 03/09/2018, Friday 35 * 03/19/2018, Monday 36 * 03/29/2018, Thursday 37 * 04/08/2018, Sunday 38 * 04/18/2018, Wednesday 39 * 04/28/2018, Saturday 40 * 05/08/2018, Tuesday 41 * 05/18/2018, Friday 42 * 05/28/2018, Monday 43 * 06/07/2018, Thursday 44 * 06/17/2018, Sunday 45 * 46 * By # of occurrences: 47 * 02/17/2018, Saturday 48 * 02/27/2018, Tuesday 49 * 03/09/2018, Friday 50 * 03/19/2018, Monday 51 * 03/29/2018, Thursday 52 * 04/08/2018, Sunday 53 * 04/18/2018, Wednesday 54 * 04/28/2018, Saturday 55 * 05/08/2018, Tuesday 56 * 05/18/2018, Friday 57 */