WeeklyRecurrenceStrategy Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
Generates occurrences on one or more selected weekdays every fixed number of weeks, such as every Monday and Friday or every second Tuesday.
public sealed class WeeklyRecurrenceStrategy : IDateRecurrenceStrategy
- Inheritance
-
WeeklyRecurrenceStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
The recurrence is anchor-based and day-of-week based; it never consults CurrentCulture for a week boundary. For a weekly interval an anchor is optional because every week participates; for a multi-week interval an anchor is required and defines the phase of each selected weekday series. Occurrences are returned in ascending chronological order regardless of the order the weekdays were declared, with no duplicates.
// Every second Tuesday, phased from 6 January 2026.
var recurrence = new WeeklyRecurrenceStrategy(new[] { DayOfWeek.Tuesday }, 2, new DateOnly(2026, 1, 6));
Constructors
WeeklyRecurrenceStrategy(IEnumerable<DayOfWeek>, int, DateOnly?)
Initializes a new instance of the WeeklyRecurrenceStrategy class.
public WeeklyRecurrenceStrategy(IEnumerable<DayOfWeek> daysOfWeek, int intervalWeeks = 1, DateOnly? anchorDate = null)
Parameters
daysOfWeekIEnumerable<DayOfWeek>The weekdays to generate occurrences on.
intervalWeeksintThe number of weeks between consecutive occurrences of each weekday.
anchorDateDateOnly?The anchor date that phases each weekday series, or null when the interval is one week.
Exceptions
- ArgumentNullException
daysOfWeekis null.- ArgumentOutOfRangeException
intervalWeeksis less than one, or a member ofdaysOfWeekis not a defined DayOfWeek.- ArgumentException
daysOfWeekis empty or contains duplicates, orintervalWeeksis greater than one whileanchorDateis null.
Properties
AnchorDate
Gets the anchor date that phases each weekday series.
public DateOnly? AnchorDate { get; }
Property Value
DaysOfWeek
Gets the weekdays occurrences are generated on, in ascending order.
public IReadOnlyList<DayOfWeek> DaysOfWeek { get; }
Property Value
- IReadOnlyList<DayOfWeek>
The distinct, ordered weekdays.
IntervalWeeks
Gets the number of weeks between consecutive occurrences of each weekday.
public int IntervalWeeks { get; }
Property Value
- int
The interval in weeks.
Methods
GetOccurrences(DateRange, StrategyResolutionContext)
Calculates the occurrences of the recurrence that fall within the supplied inclusive date range.
public IEnumerable<DateOnly> GetOccurrences(DateRange range, StrategyResolutionContext context)
Parameters
rangeDateRangeThe inclusive window to generate occurrences within.
contextStrategyResolutionContextThe resolution context for referential lookups.
Returns
- IEnumerable<DateOnly>
The occurrences within
rangein ascending chronological order, without duplicates; an empty sequence when the recurrence produces no occurrence in the window.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |