Table of Contents

NthWeekdayFromRuleStrategy Class

Definition

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

Calculates the Nth occurrence of a weekday strictly before or strictly after another rule's occurrence, such as the second Monday after a festival.

public sealed class NthWeekdayFromRuleStrategy : IDateCalculationStrategy
Inheritance
NthWeekdayFromRuleStrategy
Implements
Inherited Members
Extension Methods

Remarks

A positive ordinal selects the Nth matching weekday strictly after the reference; a negative ordinal selects the Nth matching weekday strictly before it. The reference date is never counted, even when its weekday matches. The referenced rule is resolved for year + referenceYearOffset. A missing, ambiguous, circular, or recurring reference produces no occurrence.

// The second Monday after a referenced festival.
var strategy = new NthWeekdayFromRuleStrategy("festival", null, DayOfWeek.Monday, 2);

Constructors

NthWeekdayFromRuleStrategy(string, string?, DayOfWeek, int, int)

Initializes a new instance of the NthWeekdayFromRuleStrategy class.

public NthWeekdayFromRuleStrategy(string notableDateRef, string? ruleRef, DayOfWeek dayOfWeek, int ordinal, int referenceYearOffset = 0)

Parameters

notableDateRef string

The identifier of the referenced notable-date concept.

ruleRef string

The identifier of the referenced rule, or null to use its sole rule.

dayOfWeek DayOfWeek

The weekday to seek.

ordinal int

The signed ordinal count of matching weekdays from the reference.

referenceYearOffset int

The signed year offset applied to the referenced rule.

Exceptions

ArgumentNullException

notableDateRef is null.

ArgumentOutOfRangeException

dayOfWeek is not a defined DayOfWeek, or ordinal is zero.

Properties

DayOfWeek

Gets the weekday to seek.

public DayOfWeek DayOfWeek { get; }

Property Value

DayOfWeek

The target weekday.

NotableDateRef

Gets the identifier of the referenced notable-date concept.

public string NotableDateRef { get; }

Property Value

string

The referenced concept id.

Ordinal

Gets the signed ordinal count of matching weekdays from the reference.

public int Ordinal { get; }

Property Value

int

The ordinal; positive counts strictly after, negative strictly before.

ReferenceYearOffset

Gets the signed year offset applied to the referenced rule.

public int ReferenceYearOffset { get; }

Property Value

int

The reference year offset.

RuleRef

Gets the identifier of the referenced rule.

public string? RuleRef { get; }

Property Value

string

The referenced rule id, or null when the sole rule is used.

Methods

Calculate(int, StrategyResolutionContext)

Calculates the occurrence of the notable date in the supplied Gregorian year.

public DateOnly? Calculate(int year, StrategyResolutionContext context)

Parameters

year int

The Gregorian year in which to calculate the occurrence.

context StrategyResolutionContext

The resolution context used by referential strategies to resolve other rules.

Returns

DateOnly?

The calculated occurrence, or null when the strategy produces no occurrence in year (for example a 29 February rule in a non-leap year).

Applies to

ProductVersions
.NET8, 10

See Also