OffsetFromRuleStrategy Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
Calculates a notable date as a fixed day offset from another rule's occurrence, such as Good Friday two days before Easter Sunday.
public sealed class OffsetFromRuleStrategy : IDateCalculationStrategy
- Inheritance
-
OffsetFromRuleStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
The referenced rule is identified by stable id. When the reference cannot be resolved unambiguously the strategy produces no occurrence; the loader reports the unresolved or ambiguous reference as a validation error.
// The rule shape this strategy realizes - a day count from another concept's rule
// (Good Friday: two days before Easter Sunday). The referenced concept must exist
// in the document (or arrive via an import).
NotableDateResource resource = NotableDateDocumentBuilder.Create("demo")
.AddImport("christian-western", i => i.Use("easter-sunday"))
.AddNotableDate("good-friday", "Good Friday", NotableDateCategory.PublicHoliday, c => c
.AddRule("default", r => r.OffsetFromRule("easter-sunday", -2)))
.Build(CommonNotableDateResources.Resolver);
Constructors
OffsetFromRuleStrategy(string, string?, int)
Initializes a new instance of the OffsetFromRuleStrategy class.
public OffsetFromRuleStrategy(string notableDateRef, string? ruleRef, int offsetDays)
Parameters
notableDateRefstringThe identifier of the referenced notable-date concept.
ruleRefstringThe identifier of the referenced rule, or null to use its sole rule.
offsetDaysintThe signed number of days to offset from the referenced occurrence.
Exceptions
- ArgumentNullException
notableDateRefis null.
Properties
NotableDateRef
Gets the identifier of the referenced notable-date concept.
public string NotableDateRef { get; }
Property Value
- string
The referenced concept id.
OffsetDays
Gets the signed number of days to offset from the referenced occurrence.
public int OffsetDays { get; }
Property Value
- int
The day 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 |