lpil / icalendar

🗓️ A small library for reading and writing ICalendar files.
MIT License
103 stars 56 forks source link

Google calendar - DTSTART/DTEND in UTC not localizing correctly without TZID #33

Closed darrenklein closed 5 years ago

darrenklein commented 5 years ago

Hello, thank you so much for your work on this project.

I recently updated from version 0.7.1 to 0.8.0 and started getting reports from users of incorrect event start and end times in their Google calendar .ics files. A quick glance at your commit history showed me what had happened - see https://github.com/lpil/icalendar/commit/1dda5fcfb9d0019b33344686b0dc99123a458b23

In a nutshell, I've been using your library to send events where the DTSTART and DTEND values are in UTC - previously, those were written like

DTEND;TZID=Etc/UTC:20190426T190000
DTSTART;TZID=Etc/UTC:20190426T180000

but the latest release writes them like

DTEND:20190426T190000
DTSTART:20190426T180000

where the TZID prefix has been removed from the datetime when operating in UTC - @tcitworld pointed to the documentation at https://icalendar.org/iCalendar-RFC-5545/3-2-19-time-zone-identifier.html which makes it clear that this is the correct way to handle UTC.

However, it seems like some calendaring tools (or at the very least, Google calendar, which is the only one I've been able to test this with) do need that TZID=Etc/UTC: to know that you're dealing with UTC.

I'm on the east coast of the US, Eastern Standard Time. I sent myself two emails at my Gmail account with .ics files attached, one with each set of data from above - the first one was interpreted correctly by Google calendar as running from 2:00pm - 3:00pm EST, while the second shows 6:00pm - 7:00pm EST.

For the time being, I'll be fine rolling back to use version 0.7.1, but I wanted to make you aware of this issue, with the caveat that it needs further investigation (again, I have only tested with Google calendar).

I'm interested in hearing your thoughts on this. Again, thank you so much for your hard work.

darrenklein commented 5 years ago

I did a little experiment, and I found that appending a Z to the end of the DTSTART/DTEND values will correctly set those values in UTC. So, for example, changing the call to build/2 to:

  def build(key, date = %DateTime{time_zone: "Etc/UTC"}) do
    "#{key}:#{Value.to_ics(date)}Z\n"
  end

did the trick, the time was set correctly in my Google calendar invite.

I can open a PR for this, but I'm not an expert in matters of .ics files by any means - I don't know if this change could cause other unforeseen problems with other calendaring tools, so I'd first like to see what you and @tcitworld think.

Thanks!

tcitworld commented 5 years ago

Indeed the Zulu suffix is probably missing here. Will have a look tomorrow.

lpil commented 5 years ago

Hi @tcitworld and @darrenklein, thank you for the bug report. Do you have a fix for this you would like to make a PR for?

darrenklein commented 5 years ago

@lpil Yep - just opened PR #34

Thanks!

lpil commented 5 years ago

Released a new version. Thank you for the find and the fix

darrenklein commented 5 years ago

@lpil @tcitworld Thanks for all of your hard work, and for the opportunity to contribute to this project.

lpil commented 5 years ago

Credit goes to @tcitworld, I mostly just press "release" these days. :)