Table of Contents

AdjustmentPolicy Class

Definition

Namespace
Bodu.Globalization.Calendar
Assembly
Bodu.Globalization.Calendar.dll
Package
Bodu.Globalization.Calendar 1.0.1
Source
AdjustmentPolicy.cs

Represents a reusable, named adjustment policy that transforms, supplements, or suppresses calculated occurrences.

public sealed class AdjustmentPolicy
Inheritance
AdjustmentPolicy
Inherited Members
Extension Methods

Remarks

A policy composes a Scope that limits where it applies, a Trigger that decides whether it fires, an Action that computes the observed date, and an Emission mode that decides which occurrences are emitted. Policies are referenced by rules through stable ids.

Working-day actions honour SkipWeekends and SkipNonWorkingDates: a day is skipped while seeking the observed date if it is a weekend (when SkipWeekends is set) or already claimed by another non-working occurrence (when SkipNonWorkingDates is set). The latter is what advances a substitute past a day already taken by another holiday.

Constructors

AdjustmentPolicy(string, int, AdjustmentScope, AdjustmentTrigger, IEnumerable<DayOfWeek>, AdjustmentAction, DayOfWeek?, int, int?, bool, bool, EmissionMode, string?, bool?, int?, int?, WeekOrdinal?, string?, string?, string?, string?, IReadOnlyDictionary<string, string>?)

Initializes a new instance of the AdjustmentPolicy class.

public AdjustmentPolicy(string id, int priority, AdjustmentScope scope, AdjustmentTrigger trigger, IEnumerable<DayOfWeek> triggerWeekdays, AdjustmentAction action, DayOfWeek? actionWeekday, int actionDays, int? maxSearchDays, bool skipWeekends, bool skipNonWorkingDates, EmissionMode emission, string? reason, bool? nonWorking, int? triggerMonth = null, int? triggerDay = null, WeekOrdinal? triggerWeekOrdinal = null, string? actionNotableDateRef = null, string? actionRuleRef = null, string? actionHandlerKey = null, string? triggerHandlerKey = null, IReadOnlyDictionary<string, string>? handlerParameters = null)

Parameters

id string

The stable identifier of the policy.

priority int

The selection priority of the policy.

scope AdjustmentScope

The scope that limits where the policy applies.

trigger AdjustmentTrigger

The condition under which the policy fires.

triggerWeekdays IEnumerable<DayOfWeek>

The weekdays the IfDayOfWeek trigger reacts to.

action AdjustmentAction

The transformation applied when the policy fires.

actionWeekday DayOfWeek?

The target weekday for weekday-seeking actions, or null when unused.

actionDays int

The day delta for AddDays.

maxSearchDays int?

The maximum number of days a working-day search may scan, or null for the default.

skipWeekends bool

Whether a working-day search skips weekends.

skipNonWorkingDates bool

Whether a working-day search skips days already claimed by other non-working occurrences.

emission EmissionMode

The emission mode applied when the policy fires.

reason string

The reason recorded against an observed occurrence, if any.

nonWorking bool?

The non-working-day flag applied to the observed occurrence, if specified.

triggerMonth int?

The comparison month for the fixed-date triggers, or null.

triggerDay int?

The comparison day for the fixed-date triggers, or null.

triggerWeekOrdinal WeekOrdinal?

The week ordinal for IfNthOccurrenceInMonth, or null.

actionNotableDateRef string

The referenced concept for ReplaceWithRule, or null.

actionRuleRef string

The referenced rule for ReplaceWithRule, or null to use the referenced concept's sole rule.

actionHandlerKey string

The handler key for Custom, or null.

triggerHandlerKey string

The handler key for Custom, or null.

handlerParameters IReadOnlyDictionary<string, string>

The author-supplied parameters passed to custom trigger and action handlers, or null for none.

Exceptions

ArgumentNullException

id, scope, or triggerWeekdays is null.

Properties

Action

Gets the transformation applied when the policy fires.

public AdjustmentAction Action { get; }

Property Value

AdjustmentAction

The AdjustmentAction.

ActionDays

Gets the day delta applied by AddDays.

public int ActionDays { get; }

Property Value

int

The signed number of days.

ActionHandlerKey

Gets the handler key that binds Custom to a registered IAdjustmentHandler.

public string? ActionHandlerKey { get; }

Property Value

string

The handler key, or null when unused.

ActionNotableDateRef

Gets the referenced concept whose occurrence supplies the observed date for ReplaceWithRule.

public string? ActionNotableDateRef { get; }

Property Value

string

The referenced concept identifier, or null when unused.

ActionRuleRef

Gets the referenced rule whose occurrence supplies the observed date for ReplaceWithRule.

public string? ActionRuleRef { get; }

Property Value

string

The referenced rule identifier, or null to use the referenced concept's sole rule.

ActionWeekday

Gets the target weekday for weekday-seeking actions.

public DayOfWeek? ActionWeekday { get; }

Property Value

DayOfWeek?

The target weekday, or null when the action does not seek a weekday.

Emission

Gets the emission mode applied when the policy fires.

public EmissionMode Emission { get; }

Property Value

EmissionMode

The EmissionMode.

HandlerParameters

Gets the author-supplied parameters passed to custom trigger and action handlers.

public IReadOnlyDictionary<string, string> HandlerParameters { get; }

Property Value

IReadOnlyDictionary<string, string>

The parameter map; empty when the policy declares none. The engine treats the values as opaque.

Id

Gets the stable identifier of the policy.

public string Id { get; }

Property Value

string

The policy id.

MaxSearchDays

Gets the maximum number of days a working-day search may scan.

public int? MaxSearchDays { get; }

Property Value

int?

The configured search bound, or null when the default applies.

NonWorking

Gets the non-working-day flag applied to the observed occurrence.

public bool? NonWorking { get; }

Property Value

bool?

The flag, or null when the rule's default applies.

Priority

Gets the selection priority of the policy.

public int Priority { get; }

Property Value

int

The numeric priority.

Reason

Gets the reason recorded against an observed occurrence.

public string? Reason { get; }

Property Value

string

The reason text, or null when none is configured.

Scope

Gets the scope that limits where the policy applies.

public AdjustmentScope Scope { get; }

Property Value

AdjustmentScope

The AdjustmentScope.

SkipNonWorkingDates

Gets a value indicating whether a working-day search skips days already claimed by other non-working occurrences.

public bool SkipNonWorkingDates { get; }

Property Value

bool

true when occupied non-working days are skipped; otherwise false.

SkipWeekends

Gets a value indicating whether a working-day search skips weekends.

public bool SkipWeekends { get; }

Property Value

bool

true when weekends are skipped; otherwise false.

Trigger

Gets the condition under which the policy fires.

public AdjustmentTrigger Trigger { get; }

Property Value

AdjustmentTrigger

The AdjustmentTrigger.

TriggerDay

Gets the comparison day for the fixed-date triggers.

public int? TriggerDay { get; }

Property Value

int?

The one-based day, or null when unused.

TriggerHandlerKey

Gets the handler key that binds Custom to a registered IAdjustmentTriggerHandler.

public string? TriggerHandlerKey { get; }

Property Value

string

The handler key, or null when unused.

TriggerMonth

Gets the comparison month for the fixed-date triggers.

public int? TriggerMonth { get; }

Property Value

int?

The one-based month, or null when unused.

TriggerWeekOrdinal

Gets the week ordinal for IfNthOccurrenceInMonth.

public WeekOrdinal? TriggerWeekOrdinal { get; }

Property Value

WeekOrdinal?

The configured ordinal, or null when unused.

TriggerWeekdays

Gets the weekdays the IfDayOfWeek trigger reacts to.

public IReadOnlyList<DayOfWeek> TriggerWeekdays { get; }

Property Value

IReadOnlyList<DayOfWeek>

The configured weekdays; empty when the trigger does not use weekdays.

Methods

ApplyAction(DateOnly, Func<DateOnly, bool>, WeekPattern)

Applies the policy's action to the supplied occurrence date, evaluating weekend skips against the supplied working week.

public DateOnly ApplyAction(DateOnly date, Func<DateOnly, bool> isOccupied, WeekPattern workingWeek)

Parameters

date DateOnly

The calculated occurrence date.

isOccupied Func<DateOnly, bool>

A predicate reporting whether a candidate day is already claimed by another non-working occurrence.

workingWeek WeekPattern

The working week that defines which weekdays are working days.

Returns

DateOnly

The transformed (observed) date; the input date when the action makes no change.

Exceptions

ArgumentNullException

isOccupied is null.

IsTriggered(DateOnly, WeekPattern)

Determines whether the policy fires for an occurrence on the supplied date, evaluating weekend-sensitive triggers against the supplied working week.

public bool IsTriggered(DateOnly date, WeekPattern workingWeek)

Parameters

date DateOnly

The calculated occurrence date.

workingWeek WeekPattern

The working week that defines which weekdays are working days.

Returns

bool

true if the trigger fires; otherwise false.

Remarks

The IfNonWorkingDay and IfWorkingDay triggers also depend on whether another non-working occurrence claims the date, which this method cannot determine alone; they are evaluated by the resolving service and never fire here.

Applies to

ProductVersions
.NET8, 10

See Also