MonthlyDayRecurrenceStrategy Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
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
dayOfMonthintThe one-based day of the month to generate occurrences on.
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.
invalidDayBehaviorInvalidDayOfMonthBehaviorHow a month that does not contain the requested day is handled.
Exceptions
- ArgumentOutOfRangeException
dayOfMonthis not between 1 and 31,intervalMonthsis less than one, orinvalidDayBehavioris not a defined InvalidDayOfMonthBehavior.- 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
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
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 |