New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial

Provides the abstract base class for recurrence rules.

Notes to implementers: This base class is provided to make it easier for implementers to create a recurrence rule. Implementers are encouraged to extend this base class instead of creating their own.

Definition

Namespace:Telerik.Web.UI

Assembly:Telerik.Web.UI.dll

Syntax:

C#
[TypeConverter(typeof(RecurrenceRuleConverter))]
public abstract class RecurrenceRule : ISerializable, IEquatable<RecurrenceRule>

Inheritance: objectRecurrenceRule

Derived Classes: DailyRecurrenceRuleHourlyRecurrenceRuleMonthlyRecurrenceRuleWeeklyRecurrenceRuleYearlyRecurrenceRule

Implements: IEquatable<RecurrenceRule>ISerializable

Inherited Members object.Equals(object, object)object.ReferenceEquals(object, object)object.GetType()object.MemberwiseClone()

Constructors

C#
protected RecurrenceRule()
C#
protected RecurrenceRule(SerializationInfo info, StreamingContext context)
Parameters:infoSerializationInfocontextStreamingContext

Fields

Represents an empty recurrence rule

C#
public static readonly RecurrenceRule Empty
C#
protected RecurrencePattern rulePattern
C#
protected RecurrenceRange ruleRange

Properties

C#
protected DateTime EffectiveStart { get; }

Gets or sets a list of the exception dates associated with this recurrence rule.

C#
public virtual IList<DateTime> Exceptions { get; set; }
Property Value:

A list of the exception dates associated with this recurrence rule.

Any date placed in the list will be considered a recurrence exception, i.e. an occurrence will not be generated for that date. The dates must be in universal time.

Example:
cs-api-definition
using System;
using Telerik.Web.UI;

namespace RecurrenceExamples
{
class RecurrenceExceptionsExample
{
static void Main()
{
// Creates a sample appointment that starts at 6/1/2007 3:30 PM (local time) and lasts half an hour.
Appointment recurringAppointment = new Appointment("1", Convert.ToDateTime("6/1/2007 3:30 PM"),
Convert.ToDateTime("6/1/2007 4:00 PM"), "Sample appointment");

// Creates a recurrence range, that specifies a limit of 10 occurrences for the appointment.
RecurrenceRange range = new RecurrenceRange();
range.Start = recurringAppointment.Start;
range.EventDuration = recurringAppointment.End - recurringAppointment.Start;
range.MaxOccurrences = 10;

// Creates a recurrence rule to repeat the appointment every 2 hours.
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range);

// Creates a recurrence exception for 5:30 PM (local time).
// Note that exception dates must be in universal time.
rrule.Exceptions.Add(Convert.ToDateTime("6/1/2007 5:30 PM").ToUniversalTime());

Console.WriteLine("Appointment occurrs at the following times: ");
int ix = 0;
foreach (DateTime occurrence in rrule.Occurrences)
{
ix = ix + 1;
Console.WriteLine("{0,2}: {1}", ix, occurrence.ToLocalTime());
}
}
}
}

/*
This example produces the following results:

Appointment occurrs at the following times:
1: 6/1/2007 3:30:00 PM
2: 6/1/2007 7:30:00 PM
3: 6/1/2007 9:30:00 PM
4: 6/1/2007 11:30:00 PM
5: 6/2/2007 1:30:00 AM
6: 6/2/2007 3:30:00 AM
7: 6/2/2007 5:30:00 AM
8: 6/2/2007 7:30:00 AM
9: 6/2/2007 9:30:00 AM
*/

Gets a value indicating whether this recurrence rule has associated exceptions.

C#
public bool HasExceptions { get; }
Property Value:

True if this recurrence rule has associated exceptions, false otherwise.

Gets a value indicating whether this recurrence rule yields any occurrences.

C#
public bool HasOccurrences { get; }
Property Value:

True this recurrence rule yields any occurrences, false otherwise.

Gets or sets the maximum candidates limit.

C#
public int MaximumCandidates { get; set; }
Property Value:

The maximum candidates limit.

This limit is used to prevent lockups when evaluating infinite rules without using SetEffectiveRange. The default value should not be changed under normal conditions.

Gets the evaluated occurrence times of this recurrence rule.

C#
public virtual IEnumerable<DateTime> Occurrences { get; }
Property Value:

The evaluated occurrence times of this recurrence rule.

Occurrence times are in UTC.

Example:
cs-api-definition
using System;
using Telerik.Web.UI;

namespace RecurrenceExamples
{
class HourlyRecurrenceRuleExample
{
static void Main()
{
// Creates a sample appointment that starts at 6/1/2007 3:30 PM (local time) and lasts half an hour.
Appointment recurringAppointment = new Appointment("1", Convert.ToDateTime("6/1/2007 3:30 PM"),
Convert.ToDateTime("6/1/2007 4:00 PM"), "Sample appointment");

// Creates a recurrence range, that specifies a limit of 10 occurrences for the appointment.
RecurrenceRange range = new RecurrenceRange();
range.Start = recurringAppointment.Start;
range.EventDuration = recurringAppointment.End - recurringAppointment.Start;
range.MaxOccurrences = 10;

// Creates a recurrence rule to repeat the appointment every 2 hours.
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range);

Console.WriteLine("Appointment occurrs at the following times: ");
int ix = 0;
foreach (DateTime occurrence in rrule.Occurrences)
{
ix = ix + 1;
Console.WriteLine("{0,2}: {1}", ix, occurrence.ToLocalTime());
}
}
}
}

/*
This example produces the following results:

Appointment occurrs at the following times:
1: 6/1/2007 3:30:00 PM
2: 6/1/2007 5:30:00 PM
3: 6/1/2007 7:30:00 PM
4: 6/1/2007 9:30:00 PM
5: 6/1/2007 11:30:00 PM
6: 6/2/2007 1:30:00 AM
7: 6/2/2007 3:30:00 AM
8: 6/2/2007 5:30:00 AM
9: 6/2/2007 7:30:00 AM
10: 6/2/2007 9:30:00 AM
*/

Gets the RecurrencePattern associated with this recurrence rule.

C#
public RecurrencePattern Pattern { get; }
Property Value:

The RecurrencePattern associated with this recurrence rule.

Gets the RecurrenceRange associated with this recurrence rule.

C#
public RecurrenceRange Range { get; }
Property Value:

The RecurrenceRange associated with this recurrence rule.

By calling SetEffectiveRange(DateTime, DateTime) the range of the generated occurrences can be narrowed.

Methods

Clears the effective range set by calling SetEffectiveRange(DateTime, DateTime).

C#
public void ClearEffectiveRange()

If no effective range was set, calling this method has no effect.

Overloaded. Overridden. Returns a value indicating whether this instance is equal to a specified object.

C#
public override bool Equals(object obj)
Parameters:objobject

An object to compare with this instance.

Returns:

bool

true if value is an instance of RecurrenceRule and equals the value of this instance; otherwise, false.

Overrides: object.Equals(object)

Overloaded. Overridden. Returns a value indicating whether this instance is equal to a specified RecurrenceRule object.

C#
public bool Equals(RecurrenceRule other)
Parameters:otherRecurrenceRule

An RecurrenceRule object to compare with this instance.

Returns:

bool

true if value equals the value of this instance; otherwise, false.

Implements: IEquatable<RecurrenceRule>.Equals(RecurrenceRule)

Creates a recurrence rule with the specified pattern and range.

C#
public static RecurrenceRule FromPatternAndRange(RecurrencePattern pattern, RecurrenceRange range)
Parameters:patternRecurrencePattern

The recurrence pattern.

rangeRecurrenceRange

The recurrence range.

Returns:

RecurrenceRule

The constructed recurrence rule.

Overriden. Returns the hash code for this instance.

C#
public override int GetHashCode()
Returns:

int

The hash code for this instance.

Overrides: object.GetHashCode()

Populates a SerializationInfo with the data needed to serialize this object.

C#
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters:infoSerializationInfo

The SerializationInfo to populate with data.

contextStreamingContext

The destination (see StreamingContext) for this serialization.

Implements: ISerializable.GetObjectData(SerializationInfo, StreamingContext)

C#
protected virtual DateTime GetOccurrenceStart(int index)
Parameters:indexintReturns:

DateTime

C#
protected static bool IsValidValue<T>(T value, T minValue, T maxValue) where T : IComparable
Parameters:valueTminValueTmaxValueTReturns:

bool

C#
protected virtual bool MatchAdvancedPattern(DateTime start)
Parameters:startDateTimeReturns:

bool

C#
protected bool MatchDayOfWeekMask(DateTime start)
Parameters:startDateTimeReturns:

bool

C#
protected bool MatchDayOrdinal(DateTime date)
Parameters:dateDateTimeReturns:

bool

Specifies the effective range for evaluating occurrences.

C#
public void SetEffectiveRange(DateTime start, DateTime end)
Parameters:startDateTime

The starting date of the effective range.

endDateTime

The ending date of the effective range.

Exceptions: ArgumentException

End date is before Start date.

The range is inclusive. To clear the effective range call ClearEffectiveRange().

Example:
cs-api-definition
using System;
using Telerik.Web.UI;

namespace RecurrenceExamples
{
class EffectiveRangeExample
{
static void Main()
{
// Creates a sample appointment that starts at 6/1/2007 3:30 PM (local time) and lasts half an hour.
Appointment recurringAppointment = new Appointment("1", Convert.ToDateTime("6/1/2007 3:30 PM"),
Convert.ToDateTime("6/1/2007 4:00 PM"), "Sample appointment");

// Creates a recurrence range, that specifies a limit of 10 occurrences for the appointment.
RecurrenceRange range = new RecurrenceRange();
range.Start = recurringAppointment.Start;
range.EventDuration = recurringAppointment.End - recurringAppointment.Start;
range.MaxOccurrences = 10;

// Creates a recurrence rule to repeat the appointment every 2 hours.
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range);

// Limits the effective range.
rrule.SetEffectiveRange(Convert.ToDateTime("6/1/2007 5:00 PM"), Convert.ToDateTime("6/1/2007 8:00 PM"));

Console.WriteLine("Appointment occurrs at the following times: ");
int ix = 0;
foreach (DateTime occurrence in rrule.Occurrences)
{
ix = ix + 1;
Console.WriteLine("{0,2}: {1}", ix, occurrence.ToLocalTime());
}
}
}
}

/*
This example produces the following results:

Appointment occurrs at the following times:
1: 6/1/2007 5:30:00 PM
2: 6/1/2007 7:30:00 PM
*/

Converts the recurrence rule to it's equivalent string representation.

C#
public override string ToString()
Returns:

string

The string representation of this recurrence rule.

Overrides: object.ToString()

The string representation is based on the iCalendar data format (RFC 2445).

Example:
cs-api-definition
using System;
using Telerik.Web.UI;

namespace RecurrenceExamples
{
class ParsingExample
{
static void Main()
{
// Creates a sample appointment that starts at 6/1/2007 3:30 PM (local time) and lasts half an hour.
Appointment recurringAppointment = new Appointment("1", Convert.ToDateTime("6/1/2007 3:30 PM"),
Convert.ToDateTime("6/1/2007 4:00 PM"), "Sample appointment");

// Creates a recurrence range, that specifies a limit of 10 occurrences for the appointment.
RecurrenceRange range = new RecurrenceRange();
range.Start = recurringAppointment.Start;
range.EventDuration = recurringAppointment.End - recurringAppointment.Start;
range.MaxOccurrences = 10;

// Creates a recurrence rule to repeat the appointment every 2 hours.
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range);

// Prints the string representation of the recurrence rule:
string rruleAsString = rrule.ToString();
Console.WriteLine("Recurrence rule:\n\n{0}\n", rruleAsString);

// The string representation can be stored in a database, etc.
// ...

// Then it can be reconstructed using TryParse method:
RecurrenceRule parsedRule;
RecurrenceRule.TryParse(rruleAsString, out parsedRule);
Console.WriteLine("After parsing (should be the same):\n\n{0}", parsedRule);
}
}
}

/*
This example produces the following results:

Recurrence rule:

DTSTART:20070601T123000Z
DTEND:20070601T130000Z
RRULE:FREQ=HOURLY;COUNT=10;INTERVAL=2;


After parsing (should be the same):

DTSTART:20070601T123000Z
DTEND:20070601T130000Z
RRULE:FREQ=HOURLY;COUNT=10;INTERVAL=2;
*/
C#
public string ToString(TimeZoneInfoProvider provider)
Parameters:providerTimeZoneInfoProviderReturns:

string

Creates a recurrence rule instance from it's string representation.

C#
public static bool TryParse(string input, out RecurrenceRule rrule)
Parameters:inputstring

The string representation to parse.

rruleRecurrenceRule

When this method returns, contains the recurrence rule instance, if the conversion succeeded, or null if the conversion failed. The conversion fails if the value parameter is a null reference (Nothing in Visual Basic) or represents invalid recurrence rule.

Returns:

bool

True if input was converted successfully, false otherwise.

Example:
cs-api-definition
using System;
using Telerik.Web.UI;

namespace RecurrenceExamples
{
class ParsingExample
{
static void Main()
{
// Creates a sample appointment that starts at 6/1/2007 3:30 PM (local time) and lasts half an hour.
Appointment recurringAppointment = new Appointment("1", Convert.ToDateTime("6/1/2007 3:30 PM"),
Convert.ToDateTime("6/1/2007 4:00 PM"), "Sample appointment");

// Creates a recurrence range, that specifies a limit of 10 occurrences for the appointment.
RecurrenceRange range = new RecurrenceRange();
range.Start = recurringAppointment.Start;
range.EventDuration = recurringAppointment.End - recurringAppointment.Start;
range.MaxOccurrences = 10;

// Creates a recurrence rule to repeat the appointment every 2 hours.
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range);

// Prints the string representation of the recurrence rule:
string rruleAsString = rrule.ToString();
Console.WriteLine("Recurrence rule:\n\n{0}\n", rruleAsString);

// The string representation can be stored in a database, etc.
// ...

// Then it can be reconstructed using TryParse method:
RecurrenceRule parsedRule;
RecurrenceRule.TryParse(rruleAsString, out parsedRule);
Console.WriteLine("After parsing (should be the same):\n\n{0}", parsedRule);
}
}
}

/*
This example produces the following results:

Recurrence rule:

DTSTART:20070601T123000Z
DTEND:20070601T130000Z
RRULE:FREQ=HOURLY;COUNT=10;INTERVAL=2;


After parsing (should be the same):

DTSTART:20070601T123000Z
DTEND:20070601T130000Z
RRULE:FREQ=HOURLY;COUNT=10;INTERVAL=2;
*/

Creates a recurrence rule instance from it's string representation, taking into account TimeZone offset.

C#
public static bool TryParse(string input, string timeZoneID, out RecurrenceRule rrule)
Parameters:inputstring

The string to parse.

timeZoneIDstring

The TimeZoneID.

rruleRecurrenceRule

The RecurrenceRule

Returns:

bool

RecurrenceRule if the parsing succeeded or null (Nothing in Visual Basic) if the parsing failed.

See the TryParse(string, out RecurrenceRule) overload for more information and examples.

Creates a recurrence rule instance from it's string representation.

C#
public static RecurrenceRule TryParse(string input)
Parameters:inputstring

The string to parse.

Returns:

RecurrenceRule

RecurrenceRule if the parsing succeeded or null (Nothing in Visual Basic) if the parsing failed.

See the TryParse(string, out RecurrenceRule) overload for more information and examples.

C#
protected static void ValidateValue<T>(string name, T value, T minValue, T maxValue) where T : IComparable
Parameters:namestringvalueTminValueTmaxValueT

Operators

Determines whether two specified RecurrenceRule objects have different values.

C#
public static bool operator !=(RecurrenceRule o1, RecurrenceRule o2)
Parameters:o1RecurrenceRuleo2RecurrenceRuleReturns:

bool

Determines whether two specified RecurrenceRule objects have the same value.

C#
public static bool operator ==(RecurrenceRule o1, RecurrenceRule o2)
Parameters:o1RecurrenceRuleo2RecurrenceRuleReturns:

bool