Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeZone details not being honoured in Outlook #540

Closed
StevenReid opened this issue Apr 6, 2022 · 4 comments
Closed

TimeZone details not being honoured in Outlook #540

StevenReid opened this issue Apr 6, 2022 · 4 comments

Comments

@StevenReid
Copy link

I have recently received an ICS file containing multiple events that was created using this product.
The events were created for "Eastern Standard Time" and I am in "AUS Eastern Standard Time"
When opening the Time Zone details for the event were not honoured.
The ICS file had TZID information.

When i added the TZID information to each DTSTART and DTEND entry, the correct timezone was added to each event.

@hfloyd
Copy link

hfloyd commented Apr 14, 2022

I am new to this library and using it to create ICS files via a webservice. I have noticed a similar issue with timezones.

(In this example, US Mountain Time, Start time = 11 am, End time 1:30 pm)

When I create the ICS, I add the timezone :

...
    var calendar = new Calendar();

     string tz = TZConvert.WindowsToIana(EventNode.EventTimezone.Id);
     calendar.AddTimeZone(new VTimeZone(tz));
...

And I see it added to the resulting ICS file:

BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:America/Denver
X-LIC-LOCATION:America/Denver
END:VTIMEZONE
BEGIN:VEVENT
DESCRIPTION:
DTEND:20220415T133000
DTSTAMP:20220414T163045Z
DTSTART:20220415T110000
...

But when I open the file on my own computer (In USA Eastern Time zone), the timezone displayed is Eastern - BUT, the times haven't been converted properly (it is still showing 11:00 AM - 1:30 PM, when it SHOULD show 1:00 PM - 3:30 PM for the Eastern timezone)
image

I would expect it to EITHER show the original times in the original timezone (Mountain) OR show the adjusted times in the Eastern timezone...

When I manually change the timezone in Outlook to Mountain time, and save the event - it appears on my calendar in the proper slot for Eastern time:
image

If I then Save the even as an ICS file and compare it to the generated one, these are the differences:

image

The main difference seems to be that Outlook is using Windows-style timezones rather than IANA. Additionally, there is all that Daylight saving stuff/offsets, etc. (as already discussed in #58). A bit more searching on the Issues here turned up this other post: #487, which suggests that a change to the generating code would perhaps fix it, so I updated my code to:

...
    var calendar = new Calendar();

    string tz = TZConvert.WindowsToIana(EventNode.EventTimezone.Id);
    calendar.AddTimeZone(VTimeZone.FromDateTimeZone(tz));
...

This did result in a lot more timezone data being added to the generated file:

BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:America/Denver
X-LIC-LOCATION:America/Denver
BEGIN:STANDARD
DTSTART:20201101T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
TZNAME:MST
TZOFFSETFROM:-0600
TZOFFSETTO:-0700
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20210314T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
TZNAME:MDT
TZOFFSETFROM:-0700
TZOFFSETTO:-0600
END:DAYLIGHT
END:VTIMEZONE

But Outlook treated it the same - as if it were in Eastern Time. 😢

image

I notice that the DTSTART values are different...

Additionally, in the VEVENT data there are some differences:
image

Outlook adds its time zone name to the DTSTART and DTEND values... (Additionally, I notice that Outlook names the timezone as "Mountain Standard Time", but this event is actually occurring in "Mountain Daylight Time" - but this seems to match up with the way C# TimeZoneInfo objects are identified, so it might not be relevant.)

I decided to try a different tactic - not specifying any timezone info, and changing the provide start and end dates to UTC equivalent times...

But Outlook STILL treated it as Eastern Time - just totally off, since it was using the UTC time values...

image

I also tried explicitly specifying UTC...

...
    var calendar = new Calendar();

    var tz = "Etc/UTC";
    calendar.AddTimeZone(VTimeZone.FromDateTimeZone(tz));
...

But that made no difference either.

I am kind of stuck now. If anyone has other suggestions, I'd appreciate them.

@hfloyd
Copy link

hfloyd commented Apr 15, 2022

After spending more time googling and testing, I've had a breakthrough today!

According to this post, a "Z" at the end of the DTSTART/DTEND time values indicates UTC time. I did another UTC test to see if the generated file had the "Z" appended. It did not. I looked closer at how I was generating the start/end dates for the event, and realized there were additional overloads for "CalDateTime()" which included tzid as a parameter.

I updated the code I was using to create the start/end dates like this:

new CalDateTime(DateTimeValue, "Etc/UTC");

when I re-ran the generation, the resulting file now had some more information:

BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VEVENT
DESCRIPTION:
DTEND;TZID=Etc/UTC:20220415T193000     <------ LOOK HERE
DTSTAMP:20220415T160257Z
DTSTART;TZID=Etc/UTC:20220415T170000   <------ LOOK HERE
LOCATION:
PRIORITY:5
SEQUENCE:0
SUMMARY:Event Test - Mountain Time
UID:3fe8ae15-8f18-4856-8868-791a3b95e6e6
X-ALT-DESC;FMTTYPE=text/html:
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Reminder
TRIGGER:-PT15M
END:VALARM
END:VEVENT
END:VCALENDAR

The date values didn't include the trailing "Z", BUT opening the file in Outlook properly adjusted the time to 1:00 PM - 3:30 PM for the Eastern timezone:
image

👏🏻🎉

As a final test, I went back to using the specified timezone:

            string tz = TZConvert.WindowsToIana(EventNode.EventTimezone.Id);
            calendar.AddTimeZone(VTimeZone.FromDateTimeZone(tz));
...
            Start= new CalDateTime(DateTimeValue, tz);
            End= new CalDateTime(DateTimeValue, tz);
...

The resulting file included the timezone info on the DTSTART & DTEND values:

BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VTIMEZONE
TZID:America/Denver
X-LIC-LOCATION:America/Denver
BEGIN:STANDARD
DTSTART:20201101T020000
RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11
TZNAME:MST
TZOFFSETFROM:-0600
TZOFFSETTO:-0700
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20210314T020000
RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3
TZNAME:MDT
TZOFFSETFROM:-0700
TZOFFSETTO:-0600
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
DESCRIPTION:
DTEND;TZID=America/Denver:20220415T133000        <--- HERE
DTSTAMP:20220415T161114Z
DTSTART;TZID=America/Denver:20220415T110000      <--- HERE
LOCATION:
PRIORITY:5
SEQUENCE:0
SUMMARY:Event Test - Mountain Time
UID:92a4d854-6939-4ee0-8c96-3bce4fd5a8d7
X-ALT-DESC;FMTTYPE=text/html:
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Reminder
TRIGGER:-PT15M
END:VALARM
END:VEVENT
END:VCALENDAR

@StevenReid - I think this is what you were looking for?

When I opened the ICS in Outlook, it did NOT show "Mountain Time" as the timezone - but, like for the UTC, It DID adjust the time to 1:00 PM - 3:30 PM for the Eastern timezone.

I do wish MS Outlook would better follow the standard, but this works for my purposes.
I hope this information helps others who are perplexed by timezones in Outlook. 🙂

@afortaleza
Copy link

Very helpful @hfloyd, thank you very much.

@hfloyd
Copy link

hfloyd commented May 10, 2022

@afortaleza I'm glad to document these things, so someone else can save several hours of trouble 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants