Table of Contents

DayOfWeekInMonthStrategy Class

Definition

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

Calculates a notable date that falls on the nth (or last) occurrence of a weekday within a month, such as the fourth Thursday of November or the last Monday of May.

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

Remarks

// The rule shape this strategy realizes - an nth-weekday-of-month floater
// (United States Labor Day: the first Monday of September):
NotableDateResource resource = NotableDateDocumentBuilder.Create("demo")
    .AddNotableDate("labor-day", "Labor Day", NotableDateCategory.PublicHoliday, c => c
        .AddRule("default", r => r.DayOfWeekInMonth(9, DayOfWeek.Monday, WeekOrdinal.First)))
    .Build();

Constructors

DayOfWeekInMonthStrategy(int, DayOfWeek, WeekOrdinal)

Initializes a new instance of the DayOfWeekInMonthStrategy class.

public DayOfWeekInMonthStrategy(int month, DayOfWeek dayOfWeek, WeekOrdinal weekOrdinal)

Parameters

month int

The one-based month of the occurrence.

dayOfWeek DayOfWeek

The weekday to select.

weekOrdinal WeekOrdinal

The occurrence of the weekday to select.

Exceptions

ArgumentOutOfRangeException

month is not between 1 and 12.

Properties

DayOfWeek

Gets the weekday to select.

public DayOfWeek DayOfWeek { get; }

Property Value

DayOfWeek

The target weekday.

Month

Gets the one-based month of the occurrence.

public int Month { get; }

Property Value

int

The month, where 1 is January and 12 is December.

WeekOrdinal

Gets the occurrence of the weekday to select.

public WeekOrdinal WeekOrdinal { get; }

Property Value

WeekOrdinal

The target 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