Table of Contents

RecurrenceRuleBuilder Class

Definition

Namespace
Bodu.Globalization.Recurrence
Assembly
Bodu.Globalization.Recurrence.dll
Package
Bodu.Globalization.Recurrence 1.0.0
Source
RecurrenceRuleBuilder.cs

Builds a RecurrenceRule fluently, as an alternative to parsing its textual form.

public sealed class RecurrenceRuleBuilder
Inheritance
RecurrenceRuleBuilder
Inherited Members
Extension Methods

Remarks

The builder is mutable and single-threaded; each By… or With… method returns the same instance so calls chain. Call Build() to produce the immutable rule. A builder can be reused after Build() and each By… setter replaces any previously supplied values for that rule part.

WithCount(int) and WithUntil(DateTime) are mutually exclusive; supplying one clears the other, matching the RFC 5545 rule that COUNT and UNTIL cannot both appear.

Constructors

RecurrenceRuleBuilder(RecurrenceFrequency)

Initializes a new instance of the RecurrenceRuleBuilder class for the specified frequency.

public RecurrenceRuleBuilder(RecurrenceFrequency frequency)

Parameters

frequency RecurrenceFrequency

The base recurrence period of the rule being built.

Methods

Build()

Builds the immutable RecurrenceRule from the configured components.

public RecurrenceRule Build()

Returns

RecurrenceRule

The constructed rule.

ByDay(params WeekDayNum[])

Sets the BYDAY rule part from weekday entries.

public RecurrenceRuleBuilder ByDay(params WeekDayNum[] days)

Parameters

days WeekDayNum[]

The weekday entries to select.

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

ByDay(params DayOfWeek[])

Sets the BYDAY rule part from plain weekdays, each with no positional ordinal.

public RecurrenceRuleBuilder ByDay(params DayOfWeek[] days)

Parameters

days DayOfWeek[]

The weekdays to select on every occurrence of that day within the period.

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

ByHour(params int[])

Sets the BYHOUR rule part.

public RecurrenceRuleBuilder ByHour(params int[] hours)

Parameters

hours int[]

The hours to select (0-23).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is outside the range 0 to 23.

ByMinute(params int[])

Sets the BYMINUTE rule part.

public RecurrenceRuleBuilder ByMinute(params int[] minutes)

Parameters

minutes int[]

The minutes to select (0-59).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is outside the range 0 to 59.

ByMonth(params int[])

Sets the BYMONTH rule part.

public RecurrenceRuleBuilder ByMonth(params int[] months)

Parameters

months int[]

The months to select (1-12).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is outside the range 1 to 12.

ByMonthDay(params int[])

Sets the BYMONTHDAY rule part.

public RecurrenceRuleBuilder ByMonthDay(params int[] monthDays)

Parameters

monthDays int[]

The month days to select (1-31 or -31 to -1).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is zero or outside ±31.

BySecond(params int[])

Sets the BYSECOND rule part.

public RecurrenceRuleBuilder BySecond(params int[] seconds)

Parameters

seconds int[]

The seconds to select (0-60).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is outside the range 0 to 60.

BySetPos(params int[])

Sets the BYSETPOS rule part.

public RecurrenceRuleBuilder BySetPos(params int[] setPositions)

Parameters

setPositions int[]

The set positions to select (1-366 or -366 to -1).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is zero or outside ±366.

ByWeekNo(params int[])

Sets the BYWEEKNO rule part.

public RecurrenceRuleBuilder ByWeekNo(params int[] weekNumbers)

Parameters

weekNumbers int[]

The week numbers to select (1-53 or -53 to -1).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is zero or outside ±53.

ByYearDay(params int[])

Sets the BYYEARDAY rule part.

public RecurrenceRuleBuilder ByYearDay(params int[] yearDays)

Parameters

yearDays int[]

The year days to select (1-366 or -366 to -1).

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when a value is zero or outside ±366.

WithCount(int)

Sets the occurrence count and clears any previously set UNTIL bound.

public RecurrenceRuleBuilder WithCount(int count)

Parameters

count int

The maximum number of occurrences.

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when count is less than one.

WithInterval(int)

Sets the interval - the positive multiple of the frequency between occurrences.

public RecurrenceRuleBuilder WithInterval(int interval)

Parameters

interval int

The recurrence interval.

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Exceptions

ArgumentOutOfRangeException

Thrown when interval is less than one.

WithUntil(DateTime)

Sets the inclusive upper-bound instant and clears any previously set COUNT bound.

public RecurrenceRuleBuilder WithUntil(DateTime until)

Parameters

until DateTime

The instant beyond which no occurrence is produced.

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

WithWeekStart(DayOfWeek)

Sets the day the week starts on, governing weekly-interval and week-number arithmetic.

public RecurrenceRuleBuilder WithWeekStart(DayOfWeek weekStart)

Parameters

weekStart DayOfWeek

The week-start day.

Returns

RecurrenceRuleBuilder

The same builder instance so calls can be chained.

Applies to

ProductVersions
.NET8, 10