NthWeekdayFromRuleStrategy Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
Calculates the Nth occurrence of a weekday strictly before or strictly after another rule's occurrence, such as the second Monday after a festival.
public sealed class NthWeekdayFromRuleStrategy : IDateCalculationStrategy
- Inheritance
-
NthWeekdayFromRuleStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
A positive ordinal selects the Nth matching weekday strictly after the reference; a negative ordinal selects the Nth
matching weekday strictly before it. The reference date is never counted, even when its weekday matches. The
referenced rule is resolved for year + referenceYearOffset. A missing, ambiguous, circular, or recurring
reference produces no occurrence.
// The second Monday after a referenced festival.
var strategy = new NthWeekdayFromRuleStrategy("festival", null, DayOfWeek.Monday, 2);
Constructors
NthWeekdayFromRuleStrategy(string, string?, DayOfWeek, int, int)
Initializes a new instance of the NthWeekdayFromRuleStrategy class.
public NthWeekdayFromRuleStrategy(string notableDateRef, string? ruleRef, DayOfWeek dayOfWeek, int ordinal, int referenceYearOffset = 0)
Parameters
notableDateRefstringThe identifier of the referenced notable-date concept.
ruleRefstringThe identifier of the referenced rule, or null to use its sole rule.
dayOfWeekDayOfWeekThe weekday to seek.
ordinalintThe signed ordinal count of matching weekdays from the reference.
referenceYearOffsetintThe signed year offset applied to the referenced rule.
Exceptions
- ArgumentNullException
notableDateRefis null.- ArgumentOutOfRangeException
dayOfWeekis not a defined DayOfWeek, orordinalis zero.
Properties
DayOfWeek
Gets the weekday to seek.
public DayOfWeek DayOfWeek { get; }
Property Value
- DayOfWeek
The target weekday.
NotableDateRef
Gets the identifier of the referenced notable-date concept.
public string NotableDateRef { get; }
Property Value
- string
The referenced concept id.
Ordinal
Gets the signed ordinal count of matching weekdays from the reference.
public int Ordinal { get; }
Property Value
- int
The ordinal; positive counts strictly after, negative strictly before.
ReferenceYearOffset
Gets the signed year offset applied to the referenced rule.
public int ReferenceYearOffset { get; }
Property Value
- int
The reference year offset.
RuleRef
Gets the identifier of the referenced rule.
public string? RuleRef { get; }
Property Value
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 |