MonthlyWeekdayRecurrenceStrategy Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
Generates an ordinal weekday every fixed number of months, such as the first Monday of every month or the last Friday of every third month.
public sealed class MonthlyWeekdayRecurrenceStrategy : IDateRecurrenceStrategy
- Inheritance
-
MonthlyWeekdayRecurrenceStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
The ordinal weekday in each participating month is calculated with NthWeekdayInMonth(int, int, DayOfWeek, WeekOrdinal), so Last selects the final matching weekday and a month without a fifth matching weekday simply produces no occurrence for that month rather than invalidating the recurrence. For a monthly interval an anchor is optional; a multi-month interval requires an anchor whose year and month define month zero.
// The last Friday of every month.
var recurrence = new MonthlyWeekdayRecurrenceStrategy(DayOfWeek.Friday, WeekOrdinal.Last);
Constructors
MonthlyWeekdayRecurrenceStrategy(DayOfWeek, WeekOrdinal, int, DateOnly?)
Initializes a new instance of the MonthlyWeekdayRecurrenceStrategy class.
public MonthlyWeekdayRecurrenceStrategy(DayOfWeek dayOfWeek, WeekOrdinal weekOrdinal, int intervalMonths = 1, DateOnly? anchorDate = null)
Parameters
dayOfWeekDayOfWeekThe weekday to select in each participating month.
weekOrdinalWeekOrdinalThe ordinal position of the weekday within the month.
intervalMonthsintThe number of months between consecutive occurrences.
anchorDateDateOnly?The anchor whose year and month define month zero, or null when the interval is one month.
Exceptions
- ArgumentOutOfRangeException
dayOfWeekorweekOrdinalis not a defined enumeration value, orintervalMonthsis less than one.- ArgumentException
intervalMonthsis greater than one whileanchorDateis null.
Properties
AnchorDate
Gets the anchor whose year and month define month zero.
public DateOnly? AnchorDate { get; }
Property Value
DayOfWeek
Gets the weekday selected in each participating month.
public DayOfWeek DayOfWeek { get; }
Property Value
- DayOfWeek
The target weekday.
IntervalMonths
Gets the number of months between consecutive occurrences.
public int IntervalMonths { get; }
Property Value
- int
The interval in months.
WeekOrdinal
Gets the ordinal position of the weekday within the month.
public WeekOrdinal WeekOrdinal { get; }
Property Value
- WeekOrdinal
The configured WeekOrdinal position.
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 |