Completed
Last Updated: 07 Jun 2021 15:04 by ADMIN
Release R2 2021 SP1
Patrick
Created on: 31 Mar 2021 11:35
Category: Scheduler/Reminder
Type: Bug Report
0
RadScheduler: SchedulerMultiDayView.GetAppointmentsInInterval not returning data if all-day events are available

Hello,

I found an issue when retrieving appointments using MultiDayView.GetAppointmentsInInterval

The issue occurs when creating a new appointment where AllDay is set to true
In the appointment, the Start and End date is automatically both set to the same value
When adding the appointment to the MultidayView and retrieving the appointments in interval (interval is set to 1 minute) the Appointment is not returned.
I guess the call only uses the Start and End date and not using the AllDay value

 

Grtz Patrick

1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 01 Apr 2021 11:16

Hello, Patrick, 

Please refer to the below code snippet which illustrates what is the internal implementation of the mentioned GetAppointmentsInInterval method:
        public virtual List<IEvent> GetAppointmentsInInterval(DateTimeInterval interval)
        {
            List<IEvent> currentEvents = new List<IEvent>();
            IList<IEvent> appointments = this.Appointments;
            int appointmentCount = appointments.Count;
            for (int i = 0; i < appointmentCount; i++)
            {
                IEvent currentAppointment = appointments[i];

                DateTimeInterval appointmentInterval = this.GetEventInterval(currentAppointment);
                if (interval.IntersectsWith(appointmentInterval))
                {
                    currentEvents.Add(currentAppointment);
                }
            }

            return currentEvents;
        }
        private DateTimeInterval GetEventInterval(IEvent evt)
        {
            return new DateTimeInterval(evt.Start, evt.End);
        }

Indeed, in the GetEventInterval method, it is not considered whether the Appointment is an all-day event. Hence, the returned event's interval is not correct for determining the intervals' intersection. This is the code snippet for reproducing the issue:

 Dim myStartDate As DateTime
 Sub New()
      
     InitializeComponent()

     Me.RadScheduler1.ActiveViewType = SchedulerViewType.MultiDay

     Dim multiDayView As New SchedulerMultiDayView()
     Dim startDate As Date = Date.Today
     multiDayView.Intervals.Add(startDate, 2)
     multiDayView.Intervals.Add(startDate.AddDays(4), 3)
     Me.RadScheduler1.ActiveView = multiDayView

     myStartDate = DateTime.Today.AddHours(10).AddMinutes(30)
     Dim appointment As New Appointment(myStartDate, myStartDate.AddHours(1), "Test")
     appointment.AllDay = True
     Me.RadScheduler1.Appointments.Add(appointment)

 End Sub

 Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
     Dim multiDayView As SchedulerMultiDayView = TryCast(Me.RadScheduler1.ActiveView, SchedulerMultiDayView)

     Dim endDate As DateTime = myStartDate.AddMinutes(1)
     Dim interval As DateTimeInterval = New DateTimeInterval(myStartDate, endDate)
     Dim appointments = multiDayView.GetAppointmentsInInterval(interval)
 End Sub

In the button's Click event handler the appointments collection is empty. However, if the existing appointment is not added as an all-day event, it will be returned as a result.

I have logged it in our feedback portal by making this thread public on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to use the following custom implementation:

Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
    Dim multiDayView As SchedulerMultiDayView = TryCast(Me.RadScheduler1.ActiveView, SchedulerMultiDayView)

    Dim endDate As DateTime = myStartDate.AddMinutes(1)
    Dim interval As DateTimeInterval = New DateTimeInterval(myStartDate, endDate)
    Dim appointments = GetAppointmentsInInterval(interval)
End Sub

Public Overridable Function GetAppointmentsInInterval(ByVal interval As DateTimeInterval) As List(Of IEvent)
    Dim currentEvents As List(Of IEvent) = New List(Of IEvent)()
    Dim appointments As IList(Of IEvent) = Me.RadScheduler1.Appointments
    Dim appointmentCount As Integer = appointments.Count

    For i As Integer = 0 To appointmentCount - 1
        Dim currentAppointment As IEvent = appointments(i)
        Dim appointmentInterval As DateTimeInterval = Me.GetEventInterval(currentAppointment)

        If interval.IntersectsWith(appointmentInterval) Then
            currentEvents.Add(currentAppointment)
        End If
    Next

    Return currentEvents
End Function

Private Function GetEventInterval(ByVal evt As IEvent) As DateTimeInterval
    If evt.AllDay Then
        Return New DateTimeInterval(evt.Start, evt.Start.AddHours(24).AddSeconds(-1))
    End If

    Return New DateTimeInterval(evt.Start, evt.[End])
End Function

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.