Table of Contents

WeekdayNearRuleStrategy Class

Definition

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

Calculates a weekday on, before, after, or nearest to the date produced by another rule, such as the first Monday after Easter Sunday.

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

Remarks

This is the dynamic-reference counterpart to WeekdayNearDateStrategy: the anchor is another rule's occurrence rather than a fixed month and day. The referenced rule is resolved for year + referenceYearOffset, letting a rule in one civil year anchor to a reference in an adjacent year. A missing, ambiguous, circular, or recurring reference produces no occurrence and is reported by semantic validation where statically detectable.

// The first Monday after Easter Sunday.
var strategy = new WeekdayNearRuleStrategy("easter-sunday", null, DayOfWeek.Monday, WeekdayProximity.After);

Constructors

WeekdayNearRuleStrategy(string, string?, DayOfWeek, WeekdayProximity, int)

Initializes a new instance of the WeekdayNearRuleStrategy class.

public WeekdayNearRuleStrategy(string notableDateRef, string? ruleRef, DayOfWeek dayOfWeek, WeekdayProximity direction, 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.

direction WeekdayProximity

The direction and inclusivity to apply when seeking the weekday.

referenceYearOffset int

The signed year offset applied to the referenced rule.

Exceptions

ArgumentNullException

notableDateRef is null.

ArgumentOutOfRangeException

dayOfWeek or direction is not a defined enumeration value.

Properties

DayOfWeek

Gets the weekday to seek.

public DayOfWeek DayOfWeek { get; }

Property Value

DayOfWeek

The target weekday.

Direction

Gets the direction and inclusivity applied when seeking the weekday.

public WeekdayProximity Direction { get; }

Property Value

WeekdayProximity

The configured WeekdayProximity.

NotableDateRef

Gets the identifier of the referenced notable-date concept.

public string NotableDateRef { get; }

Property Value

string

The referenced concept id.

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