Table of Contents

MonthlyDayRecurrenceStrategy Class

Definition

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

Generates an occurrence on a specified calendar day every fixed number of months, such as the 15th of every month or the 20th of every third month.

public sealed class MonthlyDayRecurrenceStrategy : IDateRecurrenceStrategy
Inheritance
MonthlyDayRecurrenceStrategy
Implements
Inherited Members
Extension Methods

Remarks

Month iteration uses a stable month anchor and re-applies the day each month, so no month-to-month clamp drift occurs: a day-31 recurrence still evaluates March as the 31st even though February has no 31st. A month that does not contain the requested day is handled by InvalidDayOfMonthBehavior - either skipped or emitted as its last calendar day. For a monthly interval an anchor is optional; a multi-month interval requires an anchor whose year and month define month zero.

// The 31st of every month, using the last day of shorter months.
var recurrence = new MonthlyDayRecurrenceStrategy(31, 1, null, InvalidDayOfMonthBehavior.UseLastDayOfMonth);

Constructors

MonthlyDayRecurrenceStrategy(int, int, DateOnly?, InvalidDayOfMonthBehavior)

Initializes a new instance of the MonthlyDayRecurrenceStrategy class.

public MonthlyDayRecurrenceStrategy(int dayOfMonth, int intervalMonths = 1, DateOnly? anchorDate = null, InvalidDayOfMonthBehavior invalidDayBehavior = InvalidDayOfMonthBehavior.Skip)

Parameters

dayOfMonth int

The one-based day of the month to generate occurrences on.

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.

invalidDayBehavior InvalidDayOfMonthBehavior

How a month that does not contain the requested day is handled.

Exceptions

ArgumentOutOfRangeException

dayOfMonth is not between 1 and 31, intervalMonths is less than one, or invalidDayBehavior is not a defined InvalidDayOfMonthBehavior.

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.

DayOfMonth

Gets the one-based day of the month occurrences are generated on.

public int DayOfMonth { get; }

Property Value

int

The day of the month.

IntervalMonths

Gets the number of months between consecutive occurrences.

public int IntervalMonths { get; }

Property Value

int

The interval in months.

InvalidDayBehavior

Gets the behavior applied to a month that does not contain the requested day.

public InvalidDayOfMonthBehavior InvalidDayBehavior { get; }

Property Value

InvalidDayOfMonthBehavior

The configured InvalidDayOfMonthBehavior.

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