Table of Contents

WorkingDayOffsetFromRuleStrategy Class

Definition

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

Calculates a date a specified number of working days before or after another rule's occurrence, such as the last working day before a public-holiday shutdown.

public sealed class WorkingDayOffsetFromRuleStrategy : IDateCalculationStrategy
Inheritance
WorkingDayOffsetFromRuleStrategy
Implements
Inherited Members
Extension Methods

Remarks

Unlike OffsetFromRuleStrategy, which counts calendar days, this strategy counts working days: the reference date is the origin and is not counted, and non-working days (rest days and applicable non-working notable-date occurrences) are skipped. The working-day set is computed deterministically and independently of resource-declaration order by the StrategyResolutionContext. The referenced rule is resolved for year + referenceYearOffset.

// The last working day before Boxing Day.
var strategy = new WorkingDayOffsetFromRuleStrategy("boxing-day", null, -1);

Constructors

WorkingDayOffsetFromRuleStrategy(string, string?, int, int)

Initializes a new instance of the WorkingDayOffsetFromRuleStrategy class.

public WorkingDayOffsetFromRuleStrategy(string notableDateRef, string? ruleRef, int offsetWorkingDays, int referenceYearOffset = 0)

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.

offsetWorkingDays int

The signed number of working days to move from the referenced occurrence.

referenceYearOffset int

The signed year offset applied to the referenced rule.

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.

OffsetWorkingDays

Gets the signed number of working days to move from the referenced occurrence.

public int OffsetWorkingDays { get; }

Property Value

int

The working-day offset.

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

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