This is a migrated thread and some comments may be shown as answers.

RecurrenceRule and TimeZoneOffset

5 Answers 172 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Mathieu
Top achievements
Rank 1
Mathieu asked on 01 Dec 2010, 09:18 PM

Hello,

 

I have a problem to get back my appointment occurrences with the TryParse() method when I use TimeZoneOffset. Here is a procedure I use:

 

I setup my scheduler for UTC-8:

RadScheduler1.TimeZoneOffset = new TimeSpan(-8, 0, 0);

 

I enter a new appointment in the schedule: from Wednesday 1 December 2010 08h00PM to 10h00PM, with a recurrence rule: Weekly, Wednesday and Friday, up to 2 occurrences.

 

This gives me 2 appointments in the scheduler:

Wednesday 1 December 8:00pm

Friday 7 December 8:00pm

 

The data obtains in the appointment object are in UTC time zone, with values:

Start = {12/2/2010 4:00:00 AM}

End = {12/2/2010 6:00:00 AM}

RecurrenceRule = "DTSTART:20101202T040000Z\r\nDTEND:20101202T060000Z\r\nRRULE:FREQ=WEEKLY;COUNT=2;INTERVAL=1;BYDAY=WE,FR\r\n"

 

My problem appears when I use the method Telerik.Web.UI.RecurrenceRule.TryParse() on the Recurrence Rule. I obtain a rule with 2 occurrences:

 [0]  {12/3/2010 4:00:00 AM}

 [1]  {12/8/2010 4:00:00 AM}

 

This means in UTC-8:

Thursday 2 December 8:00pm

Friday 8 December 8:00pm

 

This is not what I scheduled. This appends when the start of the appointment changes of day between local time and UTC time. I think TryParse() cannot restore the occurrence properly because it do not store the time zone in which the rule has been encoded.

I am missing something? Is there another method to get my occurrence from the recurrence rule?

 

Thank you very much for your help,

Mathieu

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 08 Dec 2010, 02:48 PM
Hi Mathieu,

This is expected, because when you create an appointment for Wednesday, Dec 1, 2010 from 8pm to 10 pm with TimeZoneOffset="-08:00:00", the appointment being saved in UTC falls in the next day which is Thursday Dec 2, 2010. Now, when you parse your weekly rule, RadScheduler takes the next two possible days according the rule which are Friday, Dec 3 and  Wednesday, Dec 8.

If you want the occurrences of your parsed recurrence rule to coincide with the actual appointments in RadScheduler, please use the following workaround:

protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
   {
       if (e.Appointment.RecurrenceState == RecurrenceState.Master)
       {
           //Response.Write(e.Appointment.Start+"<br/>");
           RecurrenceRule rrule;
           RecurrenceRule.TryParse(e.Appointment.RecurrenceRule, out rrule);
           rrule.Range.Start = rrule.Range.Start.Add(RadScheduler1.TimeZoneOffset);         
           foreach (DateTime occurrence in rrule.Occurrences)
           {                     
               Response.Write(occurrence + "<br/>");
           }
       }
   }

Feel free to contact us if you have further questions.

Regards,
Peter
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Mathieu
Top achievements
Rank 1
answered on 08 Dec 2010, 04:33 PM
Thank you very much for your answer.
Indeed I get the correct occurrences days with this solution. However occurrences hours are now in local TimeZone, this is a problem since my application works in UTC TimeZone.

So I used this (ugly) workaround : If we are in case where the scheduler did not set the correct days in the recurrence rule (due to time offset), I correct the rule by shifting the days in the pattern to match what the user of scheduler really chose:

private RecurrenceRule getGoodOccurences(String recurrenceRuleFromScheduler, TimeSpan timeZoneOffset)
{
    // parse occurences with scheduler input
    Telerik.Web.UI.RecurrenceRule rule;
    if (!Telerik.Web.UI.RecurrenceRule.TryParse(recurrenceRuleFromScheduler, out rule))
        return null;
 
    // correct the input if day in system timezone is different from day in site timezone
    if ((this.Start + timeZoneOffset).Day != this.Start.Day)
    {
        RecurrenceDay recurrenceDay = rule.Pattern.DaysOfWeekMask;
        int recurrenceBits = (int)recurrenceDay;
 
        // shift days in a direction, depending of the timezone offset
        if (timeZoneOffset.Hours < 0)
        {
            recurrenceBits = recurrenceBits << 1;
            recurrenceBits &= ~((int)RecurrenceDay.EveryDay + 1);
            if ((recurrenceDay & RecurrenceDay.Saturday) == RecurrenceDay.Saturday)
                recurrenceBits++;
        }
        else
        {
            recurrenceBits = recurrenceBits >> 1;
            if ((recurrenceDay & RecurrenceDay.Sunday) == RecurrenceDay.Sunday)
                recurrenceBits |= (int)RecurrenceDay.Saturday;
        }
 
        // we have the correct days, we can recompute the RecurrenceRule
        rule.Pattern.DaysOfWeekMask = (RecurrenceDay)recurrenceBits;
    }
    return rule;
}


This code works, but maybe there is a better solution ?

Thank you very much for your time,
Mathieu

        private RecurrenceRule getGoodOccurences(String recurrenceRuleFromScheduler, TimeSpan timeZoneOffset)
        {

            // parse occurences with scheduler input
            Telerik.Web.UI.RecurrenceRule rule;
            if (!Telerik.Web.UI.RecurrenceRule.TryParse(recurrenceRuleFromScheduler, out rule))
                return null;

            // correct the input if day in system timezone is different from day in site timezone
            if ((this.Start + timeZoneOffset).Day != this.Start.Day)
            {
                RecurrenceDay recurrenceDay = rule.Pattern.DaysOfWeekMask;
                int recurrenceBits = (int)recurrenceDay;

                // shift days in a direction, depending of the timezone offset
                if (timeZoneOffset.Hours < 0)
                {
                    recurrenceBits = recurrenceBits << 1;
                    recurrenceBits &= ~((int)RecurrenceDay.EveryDay + 1);
                    if ((recurrenceDay & RecurrenceDay.Saturday) == RecurrenceDay.Saturday)
                        recurrenceBits++;
                }
                else
                {
                    recurrenceBits = recurrenceBits >> 1;
                    if ((recurrenceDay & RecurrenceDay.Sunday) == RecurrenceDay.Sunday)
                        recurrenceBits |= (int)RecurrenceDay.Saturday;
                }

                // we have the correct days, we can recompute the RecurrenceRule
                rule.Pattern.DaysOfWeekMask = (RecurrenceDay)recurrenceBits;
            }

            return rule;
        
        private RecurrenceRule getGoodOccurences(String recurrenceRuleFromScheduler, TimeSpan timeZoneOffset)
        {

            // parse occurences with scheduler input
            Telerik.Web.UI.RecurrenceRule rule;
            if (!Telerik.Web.UI.RecurrenceRule.TryParse(recurrenceRuleFromScheduler, out rule))
                return null;

            // correct the input if day in system timezone is different from day in site timezone
            if ((this.Start + timeZoneOffset).Day != this.Start.Day)
            {
                RecurrenceDay recurrenceDay = rule.Pattern.DaysOfWeekMask;
                int recurrenceBits = (int)recurrenceDay;

                // shift days in a direction, depending of the timezone offset
                if (timeZoneOffset.Hours < 0)
                {
                    recurrenceBits = recurrenceBits << 1;
                    recurrenceBits &= ~((int)RecurrenceDay.EveryDay + 1);
                    if ((recurrenceDay & RecurrenceDay.Saturday) == RecurrenceDay.Saturday)
                        recurrenceBits++;
                }
                else
                {
                    recurrenceBits = recurrenceBits >> 1;
                    if ((recurrenceDay & RecurrenceDay.Sunday) == RecurrenceDay.Sunday)
                        recurrenceBits |= (int)RecurrenceDay.Saturday;
                }

                // we have the correct days, we can recompute the RecurrenceRule
                rule.Pattern.DaysOfWeekMask = (RecurrenceDay)recurrenceBits;
            }

            return rule;
        }
0
Peter
Telerik team
answered on 13 Dec 2010, 01:49 PM
Hi Mathieu,

Thank you for sharing your findings in the forum. We haven't done an extensive research on how to best handle such cases yet, so I cannot suggest a better solution than what you have already tried. Should I discover any other approaches, I will let you know.


Greetings,
Peter
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
shashidhar ch
Top achievements
Rank 1
answered on 22 Dec 2010, 08:02 AM
i didn't get solution from this answer blog.
what i need exactly is

When i am inserting events with  weekly recurrence rule with
startdate = Dec 2nd 2010,
intervel = 2
occurrence = 6 
weekly mask = Sunday|Friday|Saturday
it is showing events on

Dec 3rd
Dec 4th
Dec 12th  

the above events are  wrong . it should show like below events

Dec 3rd
Dec 4th
Dec 5th

Please give me reply ASAP . Thanking you

Thanks & Regards
Shashi....
0
Peter
Telerik team
answered on 24 Dec 2010, 03:52 PM
Hi Shashi,

Which workaround precisely have you tried. Can you send us the code of your implementation?


Regards,
Peter
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Scheduler
Asked by
Mathieu
Top achievements
Rank 1
Answers by
Peter
Telerik team
Mathieu
Top achievements
Rank 1
shashidhar ch
Top achievements
Rank 1
Share this question
or