WeekdayNearDateStrategy 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 on, before, after, or nearest to a fixed month and day, such as the Monday on or after 24 May.
public sealed class WeekdayNearDateStrategy : IDateCalculationStrategy
- Inheritance
-
WeekdayNearDateStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
// The rule shape this strategy realizes - the weekday nearest a fixed anchor date
// (the Monday closest to 12 June):
NotableDateResource resource = NotableDateDocumentBuilder.Create("demo")
.AddNotableDate("kings-birthday", "King's Birthday", NotableDateCategory.PublicHoliday, c => c
.AddRule("default", r => r.WeekdayNearDate(6, 12, DayOfWeek.Monday, WeekdayProximity.Nearest)))
.Build();
Constructors
WeekdayNearDateStrategy(int, int, DayOfWeek, WeekdayProximity)
Initializes a new instance of the WeekdayNearDateStrategy class.
public WeekdayNearDateStrategy(int month, int day, DayOfWeek dayOfWeek, WeekdayProximity direction)
Parameters
monthintThe one-based anchor month.
dayintThe one-based anchor day.
dayOfWeekDayOfWeekThe weekday to seek.
directionWeekdayProximityThe direction and inclusivity to apply when seeking the weekday.
Exceptions
- ArgumentOutOfRangeException
monthis not between 1 and 12, ordayis not between 1 and 31.
Properties
Day
Gets the one-based anchor day.
public int Day { get; }
Property Value
- int
The anchor day.
DayOfWeek
Gets the weekday to seek.
public DayOfWeek DayOfWeek { get; }
Property Value
- DayOfWeek
The target weekday.
Direction
Gets the direction and inclusivity applied when seeking the weekday.
public WeekdayProximity Direction { get; }
Property Value
- WeekdayProximity
The configured WeekdayProximity.
Month
Gets the one-based anchor month.
public int Month { get; }
Property Value
- int
The anchor month.
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 |