NotableDateRuleBuilder Class
Definition
- Namespace
- Bodu.Globalization.Calendar.Builder
- Assembly
- Bodu.Globalization.Calendar.Builder.dll
- Package
- Bodu.Globalization.Calendar.Builder 1.0.0
Provides a fluent surface for authoring a single rule: its selection scalars, applicability scope, exactly one calculation strategy, rule-specific tags, and the adjustment policies applied to its occurrences.
public sealed class NotableDateRuleBuilder
- Inheritance
-
NotableDateRuleBuilder
- Inherited Members
- Extension Methods
Examples
// U.S. Thanksgiving: the fourth Thursday of November, scoped to the United States.
definition.AddRule("us", r => r
.ForTerritory("US")
.DayOfWeekInMonth(11, DayOfWeek.Thursday, WeekOrdinal.Fourth)
.AsNonWorking());
Remarks
A rule must declare exactly one calculation strategy - for example Fixed(int, int, bool, bool),
DayOfWeekInMonth(int, DayOfWeek, WeekOrdinal),
WeekdayNearDate(int, int, DayOfWeek, WeekdayProximity),
OffsetFromRule(string, int, string?), or Algorithm(string). Scope the rule to a
calendar, territories, or a year window with the For… / …Year(s) members, and attach reusable
adjustment policies with WithAdjustment(string). Configure the builder inside
AddRule(string, Action<NotableDateRuleBuilder>).
Methods
AddTag(string)
Adds a single tag to the rule.
public NotableDateRuleBuilder AddTag(string tag)
Parameters
tagstringThe tag value.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
tagis null, empty, or white-space.
Algorithm(string)
Configures the rule with an algorithm strategy that resolves its date from a named built-in or custom algorithm.
public NotableDateRuleBuilder Algorithm(string key)
Parameters
keystringThe algorithm key, for example
"western-easter".
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
keyis null, empty, or white-space.- InvalidOperationException
A strategy has already been configured on this rule.
AnchorYear(int)
Sets the anchor year used by interval recurrence.
public NotableDateRuleBuilder AnchorYear(int year)
Parameters
yearintThe anchor year.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
AsNonWorking(bool)
Sets whether occurrences of the rule are non-working days.
public NotableDateRuleBuilder AsNonWorking(bool value = true)
Parameters
valueboolThe non-working flag.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
DailyInterval(DateOnly, int)
Configures the rule with a daily-interval recurrence.
public NotableDateRuleBuilder DailyInterval(DateOnly anchorDate, int intervalDays = 1)
Parameters
anchorDateDateOnlyThe anchor date that defines occurrence zero and the phase of the series.
intervalDaysintThe number of calendar days between consecutive occurrences.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- InvalidOperationException
An occurrence source has already been configured on this rule.
DayOfWeekInMonth(int, DayOfWeek, WeekOrdinal)
Configures the rule with a day-of-week-in-month strategy.
public NotableDateRuleBuilder DayOfWeekInMonth(int month, DayOfWeek dayOfWeek, WeekOrdinal weekOrdinal)
Parameters
monthintThe one-based month number.
dayOfWeekDayOfWeekThe day of the week to select.
weekOrdinalWeekOrdinalThe ordinal position of the weekday within the month.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
monthis outside 1 to 12.- InvalidOperationException
A strategy has already been configured on this rule.
DayOfYear(int)
Configures the rule with a day-of-year strategy.
public NotableDateRuleBuilder DayOfYear(int ordinal)
Parameters
ordinalintThe signed ordinal position of the day within the year.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- InvalidOperationException
An occurrence source has already been configured on this rule.
EveryYears(int)
Sets the recurrence interval in years for the rule's applicability.
public NotableDateRuleBuilder EveryYears(int years)
Parameters
yearsintThe interval between applicable years.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
yearsis less than 1.
ExceptYears(params int[])
Replaces the rule's exception year list with the supplied years.
public NotableDateRuleBuilder ExceptYears(params int[] years)
Parameters
yearsint[]The years for which the rule is suppressed.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
yearsis null.
Fixed(int, int, bool, bool)
Configures the rule with a fixed day-of-month strategy using a numeric month.
public NotableDateRuleBuilder Fixed(int month, int day, bool skipLeapMonth = false, bool sweepCalendarYears = false)
Parameters
monthintThe one-based month number.
dayintThe day of the month.
skipLeapMonthboolA value indicating whether a leap month is skipped on lunisolar calendars.
sweepCalendarYearsboolA value indicating whether the date is swept across adjacent calendar years.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
monthis outside 1 to 12 ordayis outside 1 to 31.- InvalidOperationException
A strategy has already been configured on this rule.
Fixed(string, int, bool, bool)
Configures the rule with a fixed day-of-month strategy using a month name or numeric month token.
public NotableDateRuleBuilder Fixed(string month, int day, bool skipLeapMonth = false, bool sweepCalendarYears = false)
Parameters
monthstringThe full English month name or numeric month token.
dayintThe day of the month.
skipLeapMonthboolA value indicating whether a leap month is skipped on lunisolar calendars.
sweepCalendarYearsboolA value indicating whether the date is swept across adjacent calendar years.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
monthis null, empty, or white-space.- ArgumentOutOfRangeException
dayis outside 1 to 31.- InvalidOperationException
A strategy has already been configured on this rule.
ForCalendar(CalendarSystem)
Sets the calendar system of the rule's applicability.
public NotableDateRuleBuilder ForCalendar(CalendarSystem calendar)
Parameters
calendarCalendarSystemThe calendar system.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
ForTerritories(params string[])
Replaces the rule's territory scope with the supplied collection of territory codes.
public NotableDateRuleBuilder ForTerritories(params string[] codes)
Parameters
codesstring[]The ISO territory codes.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
codesis null.
ForTerritory(string)
Adds a single territory code to the rule's applicability.
public NotableDateRuleBuilder ForTerritory(string code)
Parameters
codestringThe ISO territory code, for example
"US"or"AU-WA".
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
codeis null, empty, or white-space.
FromYear(int)
Sets the inclusive lower year bound of the rule's applicability.
public NotableDateRuleBuilder FromYear(int year)
Parameters
yearintThe first year for which the rule applies.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
IsoWeekDate(int, DayOfWeek)
Configures the rule with an ISO-week-date strategy.
public NotableDateRuleBuilder IsoWeekDate(int week, DayOfWeek dayOfWeek)
Parameters
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- InvalidOperationException
An occurrence source has already been configured on this rule.
MonthlyDay(int, int, DateOnly?, InvalidDayOfMonthBehavior)
Configures the rule with a monthly day-of-month recurrence.
public NotableDateRuleBuilder MonthlyDay(int dayOfMonth, int intervalMonths = 1, DateOnly? anchorDate = null, InvalidDayOfMonthBehavior invalidDayBehavior = InvalidDayOfMonthBehavior.Skip)
Parameters
dayOfMonthintThe one-based day of the month.
intervalMonthsintThe number of months between consecutive occurrences.
anchorDateDateOnly?The anchor whose year and month define month zero, or null.
invalidDayBehaviorInvalidDayOfMonthBehaviorHow a month without the requested day is handled.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- InvalidOperationException
An occurrence source has already been configured on this rule.
MonthlyWeekday(DayOfWeek, WeekOrdinal, int, DateOnly?)
Configures the rule with a monthly ordinal-weekday recurrence.
public NotableDateRuleBuilder MonthlyWeekday(DayOfWeek dayOfWeek, WeekOrdinal weekOrdinal, int intervalMonths = 1, DateOnly? anchorDate = null)
Parameters
dayOfWeekDayOfWeekThe weekday to select in each participating month.
weekOrdinalWeekOrdinalThe ordinal position of the weekday within the month.
intervalMonthsintThe number of months between consecutive occurrences.
anchorDateDateOnly?The anchor whose year and month define month zero, or null.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- InvalidOperationException
An occurrence source has already been configured on this rule.
NthWeekdayFromRule(string, DayOfWeek, int, int, string?)
Configures the rule with an nth-weekday-from-rule strategy.
public NotableDateRuleBuilder NthWeekdayFromRule(string notableDateRef, DayOfWeek dayOfWeek, int ordinal, int referenceYearOffset = 0, string? ruleRef = null)
Parameters
notableDateRefstringThe identifier of the referenced concept.
dayOfWeekDayOfWeekThe weekday to seek.
ordinalintThe signed ordinal count of matching weekdays from the reference.
referenceYearOffsetintThe signed year offset applied to the reference.
ruleRefstringThe identifier of the referenced rule, or null.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
notableDateRefis null, empty, or white-space.- InvalidOperationException
An occurrence source has already been configured on this rule.
OffsetFromRule(string, int, string?)
Configures the rule with an offset-from-rule strategy that derives its date from another rule's occurrence.
public NotableDateRuleBuilder OffsetFromRule(string notableDateRef, int offsetDays, string? ruleRef = null)
Parameters
notableDateRefstringThe identifier of the concept whose rule supplies the anchor date.
offsetDaysintThe signed day offset from the anchor occurrence.
ruleRefstringThe identifier of the anchor rule within the referenced concept, or null.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
notableDateRefis null, empty, or white-space.- InvalidOperationException
A strategy has already been configured on this rule.
OnlyYears(params int[])
Replaces the rule's exclusive year list with the supplied years.
public NotableDateRuleBuilder OnlyYears(params int[] years)
Parameters
yearsint[]The years for which the rule applies.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
yearsis null.
OrdinalDayOfMonth(int, int)
Configures the rule with an ordinal-day-of-month strategy.
public NotableDateRuleBuilder OrdinalDayOfMonth(int month, int ordinal)
Parameters
monthintThe one-based month number.
ordinalintThe signed ordinal position of the day within the month.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- InvalidOperationException
An occurrence source has already been configured on this rule.
RelativeWeekdayInMonth(int, DayOfWeek, WeekOrdinal, DayOfWeek, WeekdayProximity)
Configures the rule with a relative-weekday-in-month strategy.
public NotableDateRuleBuilder RelativeWeekdayInMonth(int month, DayOfWeek dayOfWeek, WeekOrdinal weekOrdinal, DayOfWeek relativeDayOfWeek, WeekdayProximity direction)
Parameters
monthintThe one-based month number.
dayOfWeekDayOfWeekThe anchor day of the week.
weekOrdinalWeekOrdinalThe ordinal position of the anchor weekday within the month.
relativeDayOfWeekDayOfWeekThe weekday selected relative to the anchor.
directionWeekdayProximityThe proximity rule relative to the anchor weekday.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
monthis outside 1 to 12.- InvalidOperationException
A strategy has already been configured on this rule.
ToYear(int)
Sets the inclusive upper year bound of the rule's applicability.
public NotableDateRuleBuilder ToYear(int year)
Parameters
yearintThe last year for which the rule applies.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
UntilDate(Action<NotableDateRuleBuilder>, DateBoundary, DateBoundary, EndDateSelection)
Configures the rule with a calculated end-date duration whose end anchor is produced by a second strategy.
public NotableDateRuleBuilder UntilDate(Action<NotableDateRuleBuilder> endStrategy, DateBoundary startBoundary = DateBoundary.Inclusive, DateBoundary endBoundary = DateBoundary.Inclusive, EndDateSelection selection = EndDateSelection.FirstOnOrAfterStart)
Parameters
endStrategyAction<NotableDateRuleBuilder>A configurator that selects the end strategy via one strategy method.
startBoundaryDateBoundaryWhether the start anchor is included in the span.
endBoundaryDateBoundaryWhether the end anchor is included in the span.
selectionEndDateSelectionHow the end anchor is selected relative to the start anchor.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
endStrategyis null.- InvalidOperationException
A fixed duration is already configured, a calculated duration is already configured, or the configurator did not select a strategy.
WeekdayNearDate(int, int, DayOfWeek, WeekdayProximity)
Configures the rule with a weekday-near-date strategy.
public NotableDateRuleBuilder WeekdayNearDate(int month, int day, DayOfWeek dayOfWeek, WeekdayProximity direction)
Parameters
monthintThe one-based month number.
dayintThe reference day of the month.
dayOfWeekDayOfWeekThe day of the week to select.
directionWeekdayProximityThe proximity rule relative to the reference date.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
monthis outside 1 to 12 ordayis outside 1 to 31.- InvalidOperationException
A strategy has already been configured on this rule.
WeekdayNearRule(string, DayOfWeek, WeekdayProximity, int, string?)
Configures the rule with a weekday-near-rule strategy that seeks a weekday relative to another rule's occurrence.
public NotableDateRuleBuilder WeekdayNearRule(string notableDateRef, DayOfWeek dayOfWeek, WeekdayProximity direction, int referenceYearOffset = 0, string? ruleRef = null)
Parameters
notableDateRefstringThe identifier of the referenced concept.
dayOfWeekDayOfWeekThe weekday to seek.
directionWeekdayProximityThe proximity rule relative to the reference.
referenceYearOffsetintThe signed year offset applied to the reference.
ruleRefstringThe identifier of the referenced rule, or null.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
notableDateRefis null, empty, or white-space.- InvalidOperationException
An occurrence source has already been configured on this rule.
Weekly(IEnumerable<DayOfWeek>, int, DateOnly?)
Configures the rule with a weekly recurrence on the supplied weekdays.
public NotableDateRuleBuilder Weekly(IEnumerable<DayOfWeek> daysOfWeek, int intervalWeeks = 1, DateOnly? anchorDate = null)
Parameters
daysOfWeekIEnumerable<DayOfWeek>The weekdays to generate occurrences on.
intervalWeeksintThe number of weeks between consecutive occurrences.
anchorDateDateOnly?The anchor date that phases each weekday series, or null.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
daysOfWeekis null.- InvalidOperationException
An occurrence source has already been configured on this rule.
WithAdjustment(string)
Adds a single adjustment policy reference to the rule.
public NotableDateRuleBuilder WithAdjustment(string policyRef)
Parameters
policyRefstringThe identifier of the adjustment policy to apply.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
policyRefis null, empty, or white-space.
WithAdjustments(params string[])
Replaces the rule's adjustment policy references with the supplied collection.
public NotableDateRuleBuilder WithAdjustments(params string[] policyRefs)
Parameters
policyRefsstring[]The identifiers of the adjustment policies to apply.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
policyRefsis null.
WithCategory(NotableDateCategory)
Sets the category override of the rule.
public NotableDateRuleBuilder WithCategory(NotableDateCategory category)
Parameters
categoryNotableDateCategoryThe category that overrides the concept's category.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
WithComment(string)
Sets the authoring comment of the rule.
public NotableDateRuleBuilder WithComment(string comment)
Parameters
commentstringThe comment text.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
commentis null.
WithDurationDays(int)
Sets the duration override of the rule.
public NotableDateRuleBuilder WithDurationDays(int durationDays)
Parameters
durationDaysintThe duration in days.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentOutOfRangeException
durationDaysis less than 1.
WithPriority(int)
Sets the selection priority of the rule.
public NotableDateRuleBuilder WithPriority(int priority)
Parameters
priorityintThe numeric selection priority.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
WithTags(params string[])
Replaces the rule's tags with the supplied collection.
public NotableDateRuleBuilder WithTags(params string[] tags)
Parameters
tagsstring[]The tag values.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentNullException
tagsis null.
WorkingDayInMonth(int, int)
Configures the rule with a working-day-in-month strategy.
public NotableDateRuleBuilder WorkingDayInMonth(int month, int ordinal)
Parameters
monthintThe one-based month number.
ordinalintThe signed ordinal position of the working day within the month.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- InvalidOperationException
An occurrence source has already been configured on this rule.
WorkingDayOffsetFromRule(string, int, int, string?)
Configures the rule with a working-day-offset-from-rule strategy.
public NotableDateRuleBuilder WorkingDayOffsetFromRule(string notableDateRef, int offsetWorkingDays, int referenceYearOffset = 0, string? ruleRef = null)
Parameters
notableDateRefstringThe identifier of the referenced concept.
offsetWorkingDaysintThe signed number of working days from the reference.
referenceYearOffsetintThe signed year offset applied to the reference.
ruleRefstringThe identifier of the referenced rule, or null.
Returns
- NotableDateRuleBuilder
The same NotableDateRuleBuilder instance, enabling chained calls.
Exceptions
- ArgumentException
notableDateRefis null, empty, or white-space.- InvalidOperationException
An occurrence source has already been configured on this rule.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |