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
idstringThe stable identifier of the policy.
priorityintThe selection priority of the policy.
scopeAdjustmentScopeThe scope that limits where the policy applies.
triggerAdjustmentTriggerThe condition under which the policy fires.
triggerWeekdaysIEnumerable<DayOfWeek>The weekdays the IfDayOfWeek trigger reacts to.
actionAdjustmentActionThe transformation applied when the policy fires.
actionWeekdayDayOfWeek?The target weekday for weekday-seeking actions, or null when unused.
actionDaysintThe day delta for AddDays.
maxSearchDaysint?The maximum number of days a working-day search may scan, or null for the default.
skipWeekendsboolWhether a working-day search skips weekends.
skipNonWorkingDatesboolWhether a working-day search skips days already claimed by other non-working occurrences.
emissionEmissionModeThe emission mode applied when the policy fires.
reasonstringThe reason recorded against an observed occurrence, if any.
nonWorkingbool?The non-working-day flag applied to the observed occurrence, if specified.
triggerMonthint?The comparison month for the fixed-date triggers, or null.
triggerDayint?The comparison day for the fixed-date triggers, or null.
triggerWeekOrdinalWeekOrdinal?The week ordinal for IfNthOccurrenceInMonth, or null.
actionNotableDateRefstringThe referenced concept for ReplaceWithRule, or null.
actionRuleRefstringThe referenced rule for ReplaceWithRule, or null to use the referenced concept's sole rule.
actionHandlerKeystringtriggerHandlerKeystringhandlerParametersIReadOnlyDictionary<string, string>The author-supplied parameters passed to custom trigger and action handlers, or null for none.
Exceptions
- ArgumentNullException
id,scope, ortriggerWeekdaysis null.
Properties
Action
Gets the transformation applied when the policy fires.
public AdjustmentAction Action { get; }
Property Value
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
ActionNotableDateRef
Gets the referenced concept whose occurrence supplies the observed date for ReplaceWithRule.
public string? ActionNotableDateRef { get; }
Property Value
ActionRuleRef
Gets the referenced rule whose occurrence supplies the observed date for ReplaceWithRule.
public string? ActionRuleRef { get; }
Property Value
ActionWeekday
Gets the target weekday for weekday-seeking actions.
public DayOfWeek? ActionWeekday { get; }
Property Value
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
NonWorking
Gets the non-working-day flag applied to the observed occurrence.
public bool? NonWorking { get; }
Property Value
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
Scope
Gets the scope that limits where the policy applies.
public AdjustmentScope Scope { get; }
Property Value
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
SkipWeekends
Gets a value indicating whether a working-day search skips weekends.
public bool SkipWeekends { get; }
Property Value
Trigger
Gets the condition under which the policy fires.
public AdjustmentTrigger Trigger { get; }
Property Value
TriggerDay
Gets the comparison day for the fixed-date triggers.
public int? TriggerDay { get; }
Property Value
TriggerHandlerKey
Gets the handler key that binds Custom to a registered IAdjustmentTriggerHandler.
public string? TriggerHandlerKey { get; }
Property Value
TriggerMonth
Gets the comparison month for the fixed-date triggers.
public int? TriggerMonth { get; }
Property Value
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
dateDateOnlyThe calculated occurrence date.
isOccupiedFunc<DateOnly, bool>A predicate reporting whether a candidate day is already claimed by another non-working occurrence.
workingWeekWeekPatternThe 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
isOccupiedis 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
dateDateOnlyThe calculated occurrence date.
workingWeekWeekPatternThe working week that defines which weekdays are working days.
Returns
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
| Product | Versions |
|---|---|
| .NET | 8, 10 |