Table of Contents

RelativeWeekdayInMonthStrategy Class

Definition

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

Calculates a notable date that falls on a weekday relative to an anchor weekday occurrence within a month, such as the Tuesday after the first Monday of November (United States general election day).

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

Remarks

// The rule shape this strategy realizes - a weekday positioned relative to an
// nth-weekday anchor (the Friday after the fourth Thursday of November):
NotableDateResource resource = NotableDateDocumentBuilder.Create("demo")
    .AddNotableDate("day-after-thanksgiving", "Day after Thanksgiving", NotableDateCategory.Observance, c => c
        .AddRule("default", r => r.RelativeWeekdayInMonth(
            11, DayOfWeek.Thursday, WeekOrdinal.Fourth, DayOfWeek.Friday, WeekdayProximity.After)))
    .Build();

Constructors

RelativeWeekdayInMonthStrategy(int, DayOfWeek, WeekOrdinal, DayOfWeek, WeekdayProximity)

Initializes a new instance of the RelativeWeekdayInMonthStrategy class.

public RelativeWeekdayInMonthStrategy(int month, DayOfWeek dayOfWeek, WeekOrdinal weekOrdinal, DayOfWeek relativeDayOfWeek, WeekdayProximity direction)

Parameters

month int

The one-based month of the anchor.

dayOfWeek DayOfWeek

The anchor weekday.

weekOrdinal WeekOrdinal

The occurrence of the anchor weekday in the month.

relativeDayOfWeek DayOfWeek

The weekday to seek relative to the anchor.

direction WeekdayProximity

The direction and inclusivity to apply when seeking the relative weekday.

Exceptions

ArgumentOutOfRangeException

month is not between 1 and 12.

Properties

DayOfWeek

Gets the anchor weekday.

public DayOfWeek DayOfWeek { get; }

Property Value

DayOfWeek

The anchor weekday.

Direction

Gets the direction and inclusivity applied when seeking the relative weekday.

public WeekdayProximity Direction { get; }

Property Value

WeekdayProximity

The configured WeekdayProximity.

Month

Gets the one-based month of the anchor.

public int Month { get; }

Property Value

int

The anchor month.

RelativeDayOfWeek

Gets the weekday to seek relative to the anchor.

public DayOfWeek RelativeDayOfWeek { get; }

Property Value

DayOfWeek

The relative weekday.

WeekOrdinal

Gets the occurrence of the anchor weekday in the month.

public WeekOrdinal WeekOrdinal { get; }

Property Value

WeekOrdinal

The anchor WeekOrdinal.

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