Table of Contents

MonthlyWeekdayRecurrenceStrategy Class

Definition

Namespace
Bodu.Globalization.Calendar.Algorithms
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
MonthlyWeekdayRecurrenceStrategy.cs

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

dayOfWeek DayOfWeek

The weekday to select in each participating month.

weekOrdinal WeekOrdinal

The ordinal position of the weekday within the month.

intervalMonths int

The number of months between consecutive occurrences.

anchorDate DateOnly?

The anchor whose year and month define month zero, or null when the interval is one month.

Exceptions

ArgumentOutOfRangeException

dayOfWeek or weekOrdinal is not a defined enumeration value, or intervalMonths is less than one.

ArgumentException

intervalMonths is greater than one while anchorDate is null.

Properties

AnchorDate

Gets the anchor whose year and month define month zero.

public DateOnly? AnchorDate { get; }

Property Value

DateOnly?

The anchor date, or null when the interval is one month.

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

range DateRange

The inclusive window to generate occurrences within.

context StrategyResolutionContext

The resolution context for referential lookups.

Returns

IEnumerable<DateOnly>

The occurrences within range in ascending chronological order, without duplicates; an empty sequence when the recurrence produces no occurrence in the window.

Applies to

ProductVersions
.NET8, 10

See Also