DayOfWeekInMonthStrategy Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
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
monthintThe one-based month of the occurrence.
dayOfWeekDayOfWeekThe weekday to select.
weekOrdinalWeekOrdinalThe occurrence of the weekday to select.
Exceptions
- ArgumentOutOfRangeException
monthis 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
yearintThe Gregorian year in which to calculate the occurrence.
contextStrategyResolutionContextThe resolution context used by referential strategies to resolve other rules.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |