Table of Contents

WeekdayNearDateStrategy Class

Definition

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

Calculates a notable date that falls on a weekday on, before, after, or nearest to a fixed month and day, such as the Monday on or after 24 May.

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

Remarks

// The rule shape this strategy realizes - the weekday nearest a fixed anchor date
// (the Monday closest to 12 June):
NotableDateResource resource = NotableDateDocumentBuilder.Create("demo")
    .AddNotableDate("kings-birthday", "King's Birthday", NotableDateCategory.PublicHoliday, c => c
        .AddRule("default", r => r.WeekdayNearDate(6, 12, DayOfWeek.Monday, WeekdayProximity.Nearest)))
    .Build();

Constructors

WeekdayNearDateStrategy(int, int, DayOfWeek, WeekdayProximity)

Initializes a new instance of the WeekdayNearDateStrategy class.

public WeekdayNearDateStrategy(int month, int day, DayOfWeek dayOfWeek, WeekdayProximity direction)

Parameters

month int

The one-based anchor month.

day int

The one-based anchor day.

dayOfWeek DayOfWeek

The weekday to seek.

direction WeekdayProximity

The direction and inclusivity to apply when seeking the weekday.

Exceptions

ArgumentOutOfRangeException

month is not between 1 and 12, or day is not between 1 and 31.

Properties

Day

Gets the one-based anchor day.

public int Day { get; }

Property Value

int

The anchor day.

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.

Month

Gets the one-based anchor month.

public int Month { get; }

Property Value

int

The anchor month.

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