Table of Contents

OrdinalDayOfMonthStrategy Class

Definition

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

Calculates a day by its ordinal position from the beginning or end of a Gregorian month, such as the last day of February or the second-last day of a month.

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

Remarks

A positive ordinal counts from the start of the month (1 is the first day); a negative ordinal counts from the end (-1 is the last day). The result always stays within the specified month: a positive ordinal that does not exist in a particular year and month produces no occurrence.

// The last day of February (28 or 29 depending on the year).
var strategy = new OrdinalDayOfMonthStrategy(2, -1);

Constructors

OrdinalDayOfMonthStrategy(int, int)

Initializes a new instance of the OrdinalDayOfMonthStrategy class.

public OrdinalDayOfMonthStrategy(int month, int ordinal)

Parameters

month int

The one-based month.

ordinal int

The signed ordinal position of the day within the month.

Exceptions

ArgumentOutOfRangeException

month is not between 1 and 12, or ordinal is zero or has an absolute value greater than 31.

Properties

Month

Gets the one-based month.

public int Month { get; }

Property Value

int

The month.

Ordinal

Gets the signed ordinal position of the day within the month.

public int Ordinal { get; }

Property Value

int

The ordinal; positive counts from the start, negative from the end.

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