Table of Contents

OffsetFromRuleStrategy Class

Definition

Namespace
Bodu.Globalization.Calendar.Algorithms
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
OffsetFromRuleStrategy.cs

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

notableDateRef string

The identifier of the referenced notable-date concept.

ruleRef string

The identifier of the referenced rule, or null to use its sole rule.

offsetDays int

The signed number of days to offset from the referenced occurrence.

Exceptions

ArgumentNullException

notableDateRef is 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

string

The referenced rule id, or null when the sole rule is used.

Methods

Calculate(int, StrategyResolutionContext)

Calculates the occurrence of the notable date in the supplied Gregorian year.

public DateOnly? Calculate(int year, StrategyResolutionContext context)

Parameters

year int

The Gregorian year in which to calculate the occurrence.

context StrategyResolutionContext

The 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).

Applies to

ProductVersions
.NET8, 10

See Also