0
votes

I have a recurring appointment that I created in C# with Exchange Web Services EWS 2.0 that connects to Office 365 Exchange. The appointment displays correctly in my Outlook agenda for the summer time. But after october 26 (winter time) the appointment shifted with one hour (earlier).

Apparently this has something to do with daylight saving time, but I cannot figure out how this works. I would say that the time set in the appointment and set in UTC should be automatically converted by Outlook to display it in my correct Timezone (UTC+1 Amsterdam) and DST. But it fails on DST.

As you can see in the co The relevant part of the code I use to create an appointment:

Create the service:

ExchangeService _Service = new ExchangeService ExchangeVersion.Exchange2013_SP1,TimeZoneInfo.Utc);

Set the Timezone:

appointment.StartTimeZone = TimeZoneInfo.Utc;
appointment.EndTimeZone = TimeZoneInfo.Utc;

But still the appointment is shifted when daylight saving changes.

How can I create a recurring appointment with EWS that displays correctly in Outlook throughout the year?

EDIT: Solved it thanks to venkat-ayyadevara-msft and pjneary.

Actual the time-difference between West Europe and UTC is in summertime 2 hours, and in winter time only one hour. Therefore if you set your appointment in UTC, the starttime in UTC is always the same. But since W. Europe is 2 hours appart in summer and only hour in winter, the appointment shifts in time for W. Europe TZ for one hour.

Solution: determine in which TZ the start time must be fixed, and set that timezone to your appointment. If the time retrieve from your service or database is not in that timezone, you need to convert it to the timezone of the appointment.

2

2 Answers

1
votes

The time zone on the appointment must be set as the local timezone, Amsterdam in your case. If the appointment is set with a UTC TZ, then no DST shifting will occur when EWS returns it on calendar views. You can override the TZ set on the service with the TZ on the appointment object when you make it, but if you're always going to be in one TZ it makes sense to set them the same.

1
votes

Here is a code sample that should meet your requirements using TimeZoneInfo.ConvertTimeFromUtc() i.e. Read the times in UTC from a SQL database and convert them to Amsterdam time, accounting for Daylight Savings Time.

        ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1, TimeZoneInfo.Utc);

        // Create recurring calendar item
        Appointment appointment = new Appointment(service);
        appointment.Subject = "Some subject";
        DateTime start = new DateTime(2014, 10, 14, 16, 0, 0);
        appointment.Start = TimeZoneInfo.ConvertTimeFromUtc(start, TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
        appointment.StartTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"); 
        DateTime end = new DateTime(2014, 10, 14, 17, 0, 0);
        appointment.End = TimeZoneInfo.ConvertTimeFromUtc(end, TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"));
        appointment.EndTimeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
        appointment.Location = "Some location";
        DayOfTheWeek[] days = new DayOfTheWeek[] { DayOfTheWeek.Saturday };
        appointment.Recurrence = new Recurrence.WeeklyPattern(appointment.Start.Date, 1, days);
        appointment.Recurrence.StartDate = appointment.Start.Date;
        appointment.Recurrence.NumberOfOccurrences = 20;

        // Save appointment
        appointment.Save(SendInvitationsMode.SendToNone);

Hopefully that works for you. Also, see here for time zone definitions used by EWS Managed API.

Let me know if you have any questions or need more info.

Thanks,

Venkat