AlgorithmDateStrategy Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Algorithms
- Assembly
- Bodu.Globalization.Calendar.dll
- Package
- Bodu.Globalization.Calendar 1.0.1
- Source
- AlgorithmDateStrategy.cs
Calculates a notable date using a named, algorithm-backed computation such as Easter, an equinox, a lunar-phase festival, or a gazetted date table.
public sealed class AlgorithmDateStrategy : IDateCalculationStrategy
- Inheritance
-
AlgorithmDateStrategy
- Implements
- Inherited Members
- Extension Methods
Remarks
An unrecognized key produces no occurrence; the loader reports it as a validation error so a missing algorithm surfaces during loading rather than as a silently absent date. Astronomical results are computed in the local time zone appropriate to the observance (for example Japan Standard Time for the Japanese equinox holidays).
// The rule shape this strategy realizes - a keyed algorithm supplies the date.
// Built-in keys ("western-easter", "orthodox-easter", "qingming", "vesak", "matariki", ...)
// need no registration; custom keys are registered on a NotableDateAlgorithmRegistry
// handed to both the loader and the service.
NotableDateResource resource = NotableDateDocumentBuilder.Create("demo")
.AddNotableDate("easter-sunday", "Easter Sunday", NotableDateCategory.Religious, c => c
.AddRule("default", r => r.Algorithm("western-easter")))
.Build();
Constructors
AlgorithmDateStrategy(string)
Initializes a new instance of the AlgorithmDateStrategy class.
public AlgorithmDateStrategy(string key)
Parameters
keystringThe algorithm key identifying the computation.
Exceptions
- ArgumentNullException
keyis null.
Fields
OrthodoxEasterKey
The algorithm key for Eastern Orthodox Easter Sunday.
public const string OrthodoxEasterKey = "orthodox-easter"
Field Value
WesternEasterKey
The algorithm key for Western (Gregorian) Easter Sunday.
public const string WesternEasterKey = "western-easter"
Field Value
Properties
Key
Gets the algorithm key identifying the computation.
public string Key { get; }
Property Value
- string
The algorithm key.
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
- DateOnly?
The calculated occurrence, or null when the strategy produces no occurrence in
year(for example a 29 February rule in a non-leap year).
Remarks
A key registered in the context's custom registry takes precedence over a built-in registration of the same key, so a document may override a built-in algorithm; an unrecognized key produces no occurrence.
Exceptions
- ArgumentNullException
contextis null.
IsKnownKey(string)
Determines whether the supplied algorithm key is recognized by a built-in algorithm.
public static bool IsKnownKey(string key)
Parameters
keystringThe algorithm key to test.
Returns
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |