Vladimir Prus


vladimirprus.com

Tuesday, December 23, 2014

Calendars and Timezones


It's boring to talk about calendars and time zones, but apparently major software companies still get this wrong, and a fair number of people end up very confused. For the latest example, in summer 2014, the time zone in Moscow, Russia was UTC+4, and it were to stay this way all year. Then the government decided to switch to UTC+3 in Autumn anyway, and I woke up with iPhone showing wrong time.

iOS: hardcoded time zone

Since iOS has time zone as part of OS, it still thought Moscow is UTC+4, so the clock was one hour later. That was easy to fix, I've changed iPhone time zone to a nearby UTC+3 one. And then, the calendar events started to randomly misbehave, showing one hour off, in different directions.

Google Calendar: works just fine

Suppose I create an event in Google Calendar, via web, at 18:00 Moscow (UTC+3). The invitation email to guests has a total of 4 MIME parts:
  • HTML part describing the event, with buttons to accept or decline
  • text part with a plain-text version of same
  • attachment with the application/ics content type, and invite.ics name
  • invisible part with text/calendar content type, and same content as invite.ics
Applications that understand invites will look at one of the last two parts, and see this:
DTSTART:20141210T150000Z
DTEND:20141210T160000Z
That is, the invite specifies event type as 15:00 UTC, with no timezone information, which is the correct time.

iOS: using time zone name

When I access my Google Calendar from iPhone, I see the same event on 19:00. Apparently, when accessing Google Calendar via Exchange protocol, iOS receives time zone information of the event, as "Moscow", checks its outdated database, and decides the time is 18:00 UTC+4 - one hour later than it should be.

Exchange: totally confused

Like iOS, our corporate exchange did not know about recent changes, and still thought Moscow is UTC+4, I've switched it to a time zone called "(UTC+03:00)‎‎ Kaliningrad, Minsk". When I create event at 18:00 the invitation email has 2 MIME parts:
  • text part that briefly say "When: Saturday, December 06, 2014 19:00-20:00. (UTC+03:00) Minsk", which looks right
  • invisible part with text/calendar content type
That calendar data is just the opposite to what Google does, since it names time zone:
DTSTART;TZID=Kaliningrad Standard Time:20141205T180000
DTEND;TZID=Kaliningrad Standard Time:20141205T190000
Not only that, but the name of timezone is different from the text part, and the timezone itself is also defined inside the content, as UTC+2, so that makes for 18:00 UTC+2 - one hour earlier than it should be. I don't have a good theory how it can be that broken.

Solution

What I ended up doing, and what you should do in similar situation, is find a timezone with the right offset and DST rules, but far away geographically and politically. I've ended up using Madagascar iOS and Nairobi in Exchange. Then, you should make sure that every single calendar system you use is switched to that timezone:
  • In Google Calendar, under Calendar Settings, modify Country and then Time Zone.
  • On iOS, modify Settings → General, Date & Time.
  • On iOS, also modify Setting → Mail, Contacts,Calendars → Time Zone Support.
  • In Exchange, or rather Outlook Web App, modify Settings → Regional → Current Time Zone. You can also go to Settings → Calendar and click "change your work week to the current time zone", though that does not matter much.





No comments: