ScheduleHelperGetValidYearsByOccurrence Method |
Namespace: Xcalibur.Helpers
public static DateTime[] GetValidYearsByOccurrence( DateTime startDate, int numberOfYears, int month, int day, int numberOfOccurrences = 1, int maximumYearsAllowed = 10 )
1static void Main(string[] args) 2{ 3 var startDate = new DateTime(2018, 2, 17); 4 var endDate = startDate.AddYears(5); 5 6 // Occurs on the 5th day of February of every year until the end date 7 var dates = ScheduleHelper.GetValidYearsBySchedule(startDate, endDate, 1, 2, 5); 8 Console.WriteLine($"By date range ({dates.Length}):"); 9 foreach (var date in dates) 10 { 11 Console.WriteLine($"{date:MM/dd/yyy, dddd}"); 12 } 13 14 // Spacer 15 Console.WriteLine(""); 16 17 // Occurs on the 5th day of February of every year until 50 occurrences have been reached. 18 var dates2 = ScheduleHelper.GetValidYearsByOccurrence(startDate, 1, 2, 5, 50, 5); 19 Console.WriteLine($"By # of occurrences ({dates2.Length}):"); 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 (6): 32 * 02/05/2018, Monday 33 * 02/05/2019, Tuesday 34 * 02/05/2020, Wednesday 35 * 02/05/2021, Friday 36 * 02/05/2022, Saturday 37 * 02/05/2023, Sunday 38 * 39 * By # of occurrences (6): 40 * 02/05/2018, Monday 41 * 02/05/2019, Tuesday 42 * 02/05/2020, Wednesday 43 * 02/05/2021, Friday 44 * 02/05/2022, Saturday 45 * 02/05/2023, Sunday 46 */