Table of Contents

WeeklyRecurrenceStrategy Class

Definition

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

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

daysOfWeek IEnumerable<DayOfWeek>

The weekdays to generate occurrences on.

intervalWeeks int

The number of weeks between consecutive occurrences of each weekday.

anchorDate DateOnly?

The anchor date that phases each weekday series, or null when the interval is one week.

Exceptions

ArgumentNullException

daysOfWeek is null.

ArgumentOutOfRangeException

intervalWeeks is less than one, or a member of daysOfWeek is not a defined DayOfWeek.

ArgumentException

daysOfWeek is empty or contains duplicates, or intervalWeeks is greater than one while anchorDate is null.

Properties

AnchorDate

Gets the anchor date that phases each weekday series.

public DateOnly? AnchorDate { get; }

Property Value

DateOnly?

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

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

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