Hello,
How do you get appointment times in the current time zone? I am exporting appointments using the RadScheduler.ExportToICalendar method. But the times exported in the .ics file are in the wrong time zone. Is that UTC? I'm not displaying or converting to UTC times in the scheduler for my appointments.
Thanks.
12 Answers, 1 is accepted
Please, see this kb article:
http://www.telerik.com/support/kb/aspnet-ajax/scheduler/how-to-preserve-the-time-of-the-appointments-when-exporting-to-icalendar.aspx
Kind regards,
Peter
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
That is currently working with one item; I'm looking to export a range of items. Is the process the same?
Thanks.
Yes, the approach is the same. The ExportToICalendar() method has six overloads (you can view them with the intellisense). The second overload accepts a collection of appointments in contrast to just a single appointment.
Regards,
Peter
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
For some reason, this approach, while it helped, is currently exporting events that are off by 1 hr... I have appointments at:
9:00 to 11:00
11:00 to 12:00
These are exporting as:
10:00 to 12:00
12:00 to 1:00
My code to setup the time zone is:
DateTime
aptStart = DateTime.SpecifyKind(outputAppointments[0].Start, DateTimeKind.Local);
aptStartOffset =
TimeZone.CurrentTimeZone.GetUtcOffset(aptStart) - this.rsScheduling.TimeZoneOffset;
this
.WriteCalendar(RadScheduler.ExportToICalendar(outputAppointments, aptStartOffset));
All of this code uses the same approach you use on your demo site; writing the calendar works great, but it's off 1 hr. It appears that this doesn't happen all the time, which is weird...
Do you have a sample demo which you can send via a support ticket? We couldn't replicate the problem locally.
Best wishes,
Peter
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm running into the same issue. I'm using the scheduler in eastern time zone, but the server is in central. I have followed the online demos, however my exports are an hour off as well. What seemed to fix the issue that you were having?
We managed to reproduce the problem in a local test. Here is the code that we used:
protected void Page_Load(object sender, EventArgs e) |
{ |
Appointment a = new Appointment(); |
a.Subject = "test"; |
a.Start = new DateTime(2009,06, 22, 9, 0,0); |
a.End = new DateTime(2009,06, 22, 10, 0,0); |
Session["Appointment"] = a; |
} |
private void WriteCalendar(string data) |
{ |
HttpResponse response = Page.Response; |
response.Clear(); |
response.Buffer = true; |
response.ContentType = "text/calendar"; |
response.ContentEncoding = Encoding.UTF8; |
response.Charset = "utf-8"; |
response.AddHeader("Content-Disposition","attachment;filename=\"RadSchedulerExport.ics\""); |
response.Write(data); |
response.End(); |
} |
protected void Button1_Click(object sender, EventArgs e) |
{ |
Appointment app = null; |
if (!Equals(Session["Appointment"], null)) |
{ |
app = (Appointment)Session["Appointment"]; |
TimeSpan currentOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); |
WriteCalendar(RadScheduler.ExportToICalendar(app, currentOffset)); |
} |
} |
The behavior that the appointment's time is not preserved on other time zones is expected. The reason for this is that ExportToICalendar() is a basic method and it saves the dates in UTC format. This means that the string returned by ExportToICalendar() for the above appointment and a GMT +2 time zone would be as follows:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20090622T060000Z
DTEND:20090622T070000Z
UID:20090622T085631Z-
DTSTAMP:20090622T085631Z
SUMMARY:test
END:VEVENT
END:VCALENDAR
Notice the "Z" after the start and end time. This indicates that the time is exported in UTC.
A workaround for your case would be to call ExportToICalendar() without the offset argument:
RadScheduler.ExportToICalendar(app)
and then use regular expressions to remove the "Z" for the start and end time:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Telerik Inc.//NONSGML RadScheduler//EN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20090622T090000Z
DTEND:20090622T100000Z
UID:20090622T090120Z-
DTSTAMP:20090622T090120Z
SUMMARY:test
END:VEVENT
END:VCALENDAR
Now, when you pass this string to the WriteCalendar() method, you will get the desired behavior.
We realize that using this workaround is inconvenient and it is necessitated by a limitation of RadScheduler, so please accept our apologies. We will definitely consider this case and improve RadScheduler for the future.
Greetings,
Peter
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
string data = RadScheduler.ExportToICalendar(app); |
Regex re = new Regex(@"(?<timestamp>((DTSTART)|(DTEND))[^Z]{16})Z", RegexOptions.ExplicitCapture); |
data = re.Replace(data, "${timestamp}"); |