New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Pinning all day appointments for different time zones

How To

Pin all day appointments for different time zones.

Description

RadScheduler does not keep any additional time zone information in the database. Once the offset changes, it can no longer tell which is an all-day appointment and which is an appointment that spans 24 hours.

Solution

The problem can be solved with the help of custom attributes. When an all-day event is created, we will might change the value of the custom attribute with the current time zone offset. We should also clear the attribute when the appointment is no longer all-day.

C#
protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!Page.IsPostBack)  
        {  
            RadScheduler1.TimeZoneOffset = TimeSpan.FromHours(-5);  
            TimeZoneDropDown.SelectedValue = RadScheduler1.TimeZoneOffset.ToString();  
        }  
    }  
 
    protected void TimeZoneDropDown_SelectedIndexChanged(object sender, EventArgs e)  
    {  
        RadScheduler1.TimeZoneOffset = TimeSpan.Parse(TimeZoneDropDown.SelectedValue);  
    }  
 
    protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)  
    {  
        ApplyAllDayCorrection(e.Appointment);  
    }  
 
    protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)  
    {  
        ApplyAllDayCorrection(e.ModifiedAppointment);  
    }  
 
    protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)  
    {  
        string originalTzOffsetAttrib = e.Appointment.Attributes["AllDayOriginalTimeZone"];  
        if (!string.IsNullOrEmpty(originalTzOffsetAttrib))  
        {  
            //  We need to determine the the amount of hours to correct the appointment's time  
            TimeSpan originalTzOffset = TimeSpan.Parse(originalTzOffsetAttrib);  
            //  Again, actual values should be taken from the RadScheduler instance  
            TimeSpan correction = (originalTzOffset - RadScheduler1.TimeZoneOffset);  
            //  No correction needed  
            if ((correction == TimeSpan.Zero))  
            {  
                return;  
            }  
            e.Appointment.Start = e.Appointment.Start.Add(correction);  
            e.Appointment.End = e.Appointment.End.Add(correction);  
 
            // Update the time zone  
            e.Appointment.Attributes["AllDayOriginalTimeZone"] = RadScheduler1.TimeZoneOffset.ToString();  
 
            //  If the appointment is recurring we also need to adjust the time zone of the rules  
        }  
    }  
 
    private void ApplyAllDayCorrection(Appointment apt)  
    {  
        //  We will add a custom attribute only to the all-day appointments  
        //   
        //  The criteria for all-day appointment might vary.  
        //   
        //  For example:  
        //     (RadScheduler1.UtcToDisplay(e.Appointment.Start).Date = e.Appointment.Start) And  
        //     (e.Appointment.Duration.TotalHours >= 24)  
        //   
        //  i.e. the Appointment starts at midnight and lasts more than 24 hours.  
        //   
        //   
        //  A very simple check might be:  
        if ((apt.Duration.TotalHours == 24))  
        {  
            TimeSpan currentTzOffset = RadScheduler1.TimeZoneOffset;  
            apt.Attributes["AllDayOriginalTimeZone"] = currentTzOffset.ToString();  
        }  
        else 
        {  
            //  Remove the attribute if the appointment is no longer all-day  
            apt.Attributes.Remove("AllDayOriginalTimeZone");  
        }  
    } 
In this article
How ToDescriptionSolution
Not finding the help you need?
Contact Support