Calendar frecuency not working as expect

1 Answer 69 Views
Calendar & Scheduling
Jon Ander
Top achievements
Rank 1
Jon Ander asked on 15 Jul 2022, 01:04 PM

Hi all,

The use case that I am triying to replicate is that we have some events and these can be daily/weekly/monthly/yearly recurring. So I decided to use the calendar & Scheduling component as it provided the recurrence option. When I tested the daily and weekly recurrended options it worked perfectly but to my surprise when trying to get the events recurring every month or year the trouble started.

Even tought I am using the   RecurrenceFrequency.Monthly as my frecuency rule, as we can see from the image it still seem to put it as a daily recurrence. Same happens when the  RecurrenceFrequency.Yearly option is used. Here the code used:

 foreach (Evento evento in this.ListaEventosAgenda)
            {

                EventData eventoNuevo = new EventData() {StartDate=evento.fechaInciio,EndDate=evento.fechaFin,Title=evento.titulo,LeadBorderColor = Color.FromHex(evento.colorCategoria),ItemBackgroundColor=Color.White,
                Id=evento.id,idOrg=evento.idOrg,idCategoria=evento.idCategoria,imageUrl=evento.fotoUrl,Detail=evento.descripcion,IsAllDay=evento.isAllDay,recurrenciaAnual= evento.recurrenciaAnual,recurrenciaMensual=evento.recurrenciaMensual,
                recurrenciaSemanal=evento.recurrenciaSemanal,recurrenciaDiaria=evento.recurrenciaDiaria, categoria=evento.categoria,Color = Color.FromHex(evento.colorCategoria)
                };
            //StartDate: evento.fechaInciio,endTime: evento.fechaFin,eventText: evento.titulo,leadColor: Color.FromHex("59B6B8"),itemColor: Color.White,
            //detalles: evento.descripcion, id: evento.id,imageUrl: evento.fotoUrl, IsAllDay: evento.isAllDay

             RecurrenceRule recurrenceRule = null;
                if (evento.recurrenciaDiaria)
                {
                    //var recurrencePattern = new RecurrencePattern(new int[] { }, RecurrenceDays.WeekDays, RecurrenceFrequency.Daily, 1, null, null);// { MaxOccurrences = 37 };
                    //recurrenceRule = new RecurrenceRule(recurrencePattern);


                    recurrenceRule = new RecurrenceRule(new RecurrencePattern()
                    {
                        Frequency = RecurrenceFrequency.Daily,
                    });

                    eventoNuevo.RecurrenceRule = recurrenceRule;
                }

                  else if (evento.recurrenciaSemanal)
                {

                    //var recurrencePattern = new RecurrencePattern(new int[] { }, RecurrenceDays.WeekDays, RecurrenceFrequency.Weekly, 7, null, null);// { MaxOccurrences = 37 };
                    recurrenceRule = new RecurrenceRule(new RecurrencePattern()
                    {
                        Frequency = RecurrenceFrequency.Weekly,

                    });
                    try
                    {

                    eventoNuevo.RecurrenceRule = recurrenceRule;
                    }
                    catch (Exception error)
                    {

                        Debug.WriteLine(error.Message); ;
                    }
                }

               else if (evento.recurrenciaMensual)
                {
                    var a = eventoNuevo.StartDate.DayOfWeek;
                    //var recurrencePattern = new RecurrencePattern(new int[] { }, RecurrenceDays.WeekDays, RecurrenceFrequency.Monthly, 30, null, null);// { MaxOccurrences = 37 };
                    recurrenceRule = new RecurrenceRule(new RecurrencePattern()
                    {
                        Frequency = RecurrenceFrequency.Monthly,
                    });
                    eventoNuevo.RecurrenceRule = recurrenceRule;
                }

                 else if (evento.recurrenciaAnual)
                {
                    //var recurrencePattern = new RecurrencePattern(new int[] { }, RecurrenceDays.WeekDays, RecurrenceFrequency.Daily, 365, null, null);// { MaxOccurrences = 37 };
                    recurrenceRule = new RecurrenceRule(new RecurrencePattern()
                    {
                        Frequency = RecurrenceFrequency.Yearly,

                    });
                    eventoNuevo.RecurrenceRule = recurrenceRule;
                }

                this.Events.Add(eventoNuevo);
            }

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 20 Jul 2022, 11:52 AM

Hi Jon,

Thank you for sharing the code snippet.

When you use Monthly recurrence pattern, you would also need to define the day/days of the month the event is happening through the DaysOfMonth property like this:

var eventoNuevo = new Appointment()
{
    StartDate = DateTime.Today.AddHours(10),
    EndDate = DateTime.Today.AddHours(10),
    Title = "My monthly event"
};

var recurrenceRule = new RecurrenceRule(new RecurrencePattern()
{
    Frequency = RecurrenceFrequency.Monthly,
    DaysOfMonth = new int[] { eventoNuevo.StartDate.Day },
               
}); 
eventoNuevo.RecurrenceRule = recurrenceRule;

In a similar way for the Yearly recurrence, DaysOfMonth as well as MonthOfYear properties should be defined:

var recurrenceRule = new RecurrenceRule(new RecurrencePattern()
{
    Frequency = RecurrenceFrequency.Yearly,
    DaysOfMonth = new int[] { eventoNuevo.StartDate.Day },
    MonthOfYear = eventoNuevo.StartDate.Month               
}); 

I noticed our documentation topic on the matter is not very clear on this, so I am going to update it right away.

Let me know if I can help with anything else.

Regards, 
Yana
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Calendar & Scheduling
Asked by
Jon Ander
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or