Click or drag to resize

ScheduleHelperGetValidWeeksByOccurrence Method

Gets a list of valid dates related to weeks within a number of occurrences.

Namespace:  Xcalibur.Helpers
Assembly:  Xcalibur.Helpers (in Xcalibur.Helpers.dll) Version: 1.0.1.0 (1.0.1.0)
Syntax
public static DateTime[] GetValidWeeksByOccurrence(
	DateTime startDate,
	int numberOfWeeks,
	DaysOfTheWeek[] selectedDays,
	int numberOfOccurrences = 1,
	int maximumYearsAllowed = 10
)

Parameters

startDate
Type: SystemDateTime
The start date.
numberOfWeeks
Type: SystemInt32
The number of weeks to skip per block of selected days.
selectedDays
Type: Xcalibur.HelpersDaysOfTheWeek
The selected days of the week 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(1);
  5
  6    // Occurs every 2 weeks on Sunday, Monday, and Thursday not to exceed the end date.
  7    var dates = ScheduleHelper.GetValidWeeksBySchedule(startDate, endDate, 2,
  8        new[] { Enums.DaysOfTheWeek.Sunday, Enums.DaysOfTheWeek.Monday, Enums.DaysOfTheWeek.Thursday });
  9    Console.WriteLine($"By date range ({dates.Length}):");
 10    foreach (var date in dates)
 11    {
 12        Console.WriteLine($"{date:MM/dd/yyy, dddd}");
 13    }
 14
 15    // Spacer
 16    Console.WriteLine("");
 17
 18    // Occurs up to 30 times on Sunday, Monday, and Thursday no longer than 1 year.
 19    var dates2 = ScheduleHelper.GetValidWeeksByOccurrence(startDate, 1,
 20        new[] { Enums.DaysOfTheWeek.Sunday, Enums.DaysOfTheWeek.Monday, Enums.DaysOfTheWeek.Thursday },
 21        30, 1);
 22    Console.WriteLine($"By # of occurrences ({dates2.Length}):");
 23    foreach (var date in dates2)
 24    {
 25        Console.WriteLine($"{date:MM/dd/yyyy, dddd}");
 26    }
 27
 28    // Hold
 29    Console.Read();
 30}
 31
 32/* Result:
 33 *
 34 * By date range (79):
 35 * 02/18/2018, Sunday
 36 * 02/19/2018, Monday
 37 * 02/22/2018, Thursday
 38 * 03/04/2018, Sunday
 39 * 03/05/2018, Monday
 40 * 03/08/2018, Thursday
 41 * 03/18/2018, Sunday
 42 * 03/19/2018, Monday
 43 * 03/22/2018, Thursday
 44 * 04/01/2018, Sunday
 45 * 04/02/2018, Monday
 46 * 04/05/2018, Thursday
 47 * 04/15/2018, Sunday
 48 * 04/16/2018, Monday
 49 * 04/19/2018, Thursday
 50 * 04/29/2018, Sunday
 51 * 04/30/2018, Monday
 52 * 05/03/2018, Thursday
 53 * 05/13/2018, Sunday
 54 * 05/14/2018, Monday
 55 * 05/17/2018, Thursday
 56 * 05/27/2018, Sunday
 57 * 05/28/2018, Monday
 58 * 05/31/2018, Thursday
 59 * 06/10/2018, Sunday
 60 * 06/11/2018, Monday
 61 * 06/14/2018, Thursday
 62 * 06/24/2018, Sunday
 63 * 06/25/2018, Monday
 64 * 06/28/2018, Thursday
 65 * 07/08/2018, Sunday
 66 * 07/09/2018, Monday
 67 * 07/12/2018, Thursday
 68 * 07/22/2018, Sunday
 69 * 07/23/2018, Monday
 70 * 07/26/2018, Thursday
 71 * 08/05/2018, Sunday
 72 * 08/06/2018, Monday
 73 * 08/09/2018, Thursday
 74 * 08/19/2018, Sunday
 75 * 08/20/2018, Monday
 76 * 08/23/2018, Thursday
 77 * 09/02/2018, Sunday
 78 * 09/03/2018, Monday
 79 * 09/06/2018, Thursday
 80 * 09/16/2018, Sunday
 81 * 09/17/2018, Monday
 82 * 09/20/2018, Thursday
 83 * 09/30/2018, Sunday
 84 * 10/01/2018, Monday
 85 * 10/04/2018, Thursday
 86 * 10/14/2018, Sunday
 87 * 10/15/2018, Monday
 88 * 10/18/2018, Thursday
 89 * 10/28/2018, Sunday
 90 * 10/29/2018, Monday
 91 * 11/01/2018, Thursday
 92 * 11/11/2018, Sunday
 93 * 11/12/2018, Monday
 94 * 11/15/2018, Thursday
 95 * 11/25/2018, Sunday
 96 * 11/26/2018, Monday
 97 * 11/29/2018, Thursday
 98 * 12/09/2018, Sunday
 99 * 12/10/2018, Monday
100 * 12/13/2018, Thursday
101 * 12/23/2018, Sunday
102 * 12/24/2018, Monday
103 * 12/27/2018, Thursday
104 * 01/06/2019, Sunday
105 * 01/07/2019, Monday
106 * 01/10/2019, Thursday
107 * 01/20/2019, Sunday
108 * 01/21/2019, Monday
109 * 01/24/2019, Thursday
110 * 02/03/2019, Sunday
111 * 02/04/2019, Monday
112 * 02/07/2019, Thursday
113 * 02/17/2019, Sunday
114 * 
115 * By # of occurrences (30):
116 * 02/18/2018, Sunday
117 * 02/19/2018, Monday
118 * 02/22/2018, Thursday
119 * 02/25/2018, Sunday
120 * 02/26/2018, Monday
121 * 03/01/2018, Thursday
122 * 03/04/2018, Sunday
123 * 03/05/2018, Monday
124 * 03/08/2018, Thursday
125 * 03/11/2018, Sunday
126 * 03/12/2018, Monday
127 * 03/15/2018, Thursday
128 * 03/18/2018, Sunday
129 * 03/19/2018, Monday
130 * 03/22/2018, Thursday
131 * 03/25/2018, Sunday
132 * 03/26/2018, Monday
133 * 03/29/2018, Thursday
134 * 04/01/2018, Sunday
135 * 04/02/2018, Monday
136 * 04/05/2018, Thursday
137 * 04/08/2018, Sunday
138 * 04/09/2018, Monday
139 * 04/12/2018, Thursday
140 * 04/15/2018, Sunday
141 * 04/16/2018, Monday
142 * 04/19/2018, Thursday
143 * 04/22/2018, Sunday
144 * 04/23/2018, Monday
145 * 04/26/2018, Thursday
146 */
See Also