Unplanned
Last Updated: 06 Jun 2016 13:47 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 19 May 2016 13:14
Category: Scheduler/Reminder
Type: Bug Report
1
FIX. RadScheduler - wrongly calculated event occurrences when a MonthlyRecurrenceRule is defined with 24 months interval
Please refer to the attached gif file illustrating how to reproduce the problem with the Demo application. When you define a new appointment with 24 months interval, it is expected to have this event every 2 years, not each year.

To reproduce: you can use the following code snippet as well:

MonthlyRecurrenceRule monthlyRecurrenceRule = new MonthlyRecurrenceRule(DateTime.Now, WeekDays.Monday, 2, 24);
Appointment a = new Appointment(DateTime.Now, TimeSpan.FromHours(3), "Test");
a.RecurrenceRule = monthlyRecurrenceRule;
this.radScheduler1.Appointments.Add(a);


Workaround:

 public Form1()
 {
     InitializeComponent();
     
     this.radScheduler1.AppointmentAdded += radScheduler1_AppointmentAdded;
 }

 private void radScheduler1_AppointmentAdded(object sender, AppointmentAddedEventArgs e)
 {
     MonthlyRecurrenceRule montlyRule = e.Appointment.RecurrenceRule as MonthlyRecurrenceRule;
     if (montlyRule != null)
     {
         CustomMonthlyRecurrenceRule rrule = new CustomMonthlyRecurrenceRule();
         rrule.Start = montlyRule.Start;
         rrule.End = montlyRule.End;
         rrule.Interval = montlyRule.Interval;
         rrule.Offset = montlyRule.Offset;
         rrule.WeekDays = montlyRule.WeekDays;
         rrule.WeekNumber = montlyRule.WeekNumber;
         rrule.FirstDayOfWeek = montlyRule.FirstDayOfWeek;
         rrule.Count = montlyRule.Count; 

         e.Appointment.RecurrenceRule = rrule;
     }
 }

 public class CustomMonthlyRecurrenceRule : MonthlyRecurrenceRule
 {
     public override bool MatchAdvancedPattern(DateTime date, DateTimeFormatInfo dateTimeFormat)
     {
         int monthIndex = this.Start.Value.Month - date.Month;
         DateTime calculatedNextDate = this.Start.Value.AddMonths(this.Interval);
         monthIndex = calculatedNextDate.Month - date.Month;
         if (calculatedNextDate.Year > date.Year)
         {
             return false;
         }
         if ((monthIndex % this.Interval) != 0)
         {
             return false;
         }

         if (0 != this.WeekNumber && !this.MatchWeekOfMonth(date, dateTimeFormat))
         {
             return false;
         }

         if (0 != this.DayNumber && !this.MatchDayOfMonth(date, dateTimeFormat))
         {
             return false;
         }

         if (this.WeekDays != WeekDays.None && !this.MatchDayOfWeekMask(date, dateTimeFormat.Calendar))
         {
             return false;
         }

         if (this.Offset != 0 && !this.MatchOffset(date, dateTimeFormat))
         {
             return false;
         }

         return true;
     }
 }

Attached Files:
0 comments