Click or drag to resize

ScheduleHelperGetValidYearsByOccurrence Method

Gets a list of valid dates related to years within a scheduled range.

Namespace:  Xcalibur.Helpers
Assembly:  Xcalibur.Helpers (in Xcalibur.Helpers.dll) Version: 1.0.1.0 (1.0.1.0)
Syntax
public static DateTime[] GetValidYearsByOccurrence(
	DateTime startDate,
	int numberOfYears,
	int month,
	int day,
	int numberOfOccurrences = 1,
	int maximumYearsAllowed = 10
)

Parameters

startDate
Type: SystemDateTime
The start date.
numberOfYears
Type: SystemInt32
The number of years to skip per date.
month
Type: SystemInt32
The month the event occurs.
day
Type: SystemInt32
The day of the month the event occurs.
numberOfOccurrences (Optional)
Type: SystemInt32
The number of occurrences. The default is 1.
maximumYearsAllowed (Optional)
Type: SystemInt32
The maximum years allowed. The default is 10.

Return Value

Type: DateTime
Examples
C#
 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 */
See Also