RelativeWeekdayInMonthStrategy 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 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
monthintThe one-based month of the anchor.
dayOfWeekDayOfWeekThe anchor weekday.
weekOrdinalWeekOrdinalThe occurrence of the anchor weekday in the month.
relativeDayOfWeekDayOfWeekThe weekday to seek relative to the anchor.
directionWeekdayProximityThe direction and inclusivity to apply when seeking the relative weekday.
Exceptions
- ArgumentOutOfRangeException
monthis 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
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 |