others not at all • EU example: Oct 30, 2016 3:30am and Mar 20, 2016 3:30am • DST is not always an hour: Australia/Lord_Howe has 30 min • Countries and states merrily adopt & abolish DST all the time • Morocco uses DST, but suspends it during Ramadan • …
of Easter • Replaced the Julian calendar (0.002% correction) • Considered a Catholic plot by Protestant & Orthodox churches, and adopted very late – if ever • Not exactly quirk-free either • Example: What does it mean to add 1 month to a date?
final) 2. Television time • e.g. a TV show screened at 9pm local time around the world • Note that movie premieres tend to use event time • Special case: Someone's birthday 3. Relative time (e.g. 10 days remaining until ticket sales begin) 4. Recurring time (e.g. wake me up every morning at 7am, no matter if DST or time zone changes)
by a UTC offset. • This is the same time as 2016-01-08T16:30:00Z • Separators and least significant values can be skipped • No offset means local time (discouraged) • Pro: Human-friendly, sorts naturally • Con: Requires parsing
an invitation to talk at a conference in Moscow. His slot is on November 7, 2011 at 13:00 local time. Michael marks his digital calendar, setting the event's time zone to "Moscow". On the big day, he learns to his horror that he has missed his slot by an hour. What happened?
13:00:00 local time • Moscow does not use DST in November, so his calendar app calculates and stores the following: • UTC timestamp 2011-11-07T10:00:00Z • Time zone: "Europe/Moscow" • On February 8, 2011, Russia decides to stay on "permanent summer time" (UTC+4) after the next shift to DST on March 27. Global time zone databases are updated accordingly.
zone database. From now on, it will interpret "Europe/Moscow" as UTC+4:00. • When Michael looks at his calendar in November, the device reconstructs the displayed time from the UTC timestamp and the time zone, showing November 7, 2011 14:00:00. • Folks in Moscow miss a great talk – thanks to a sloppy developer.
this stuff yourself! • Never write code like tuesday = monday + 24*60*60 • Convert input to UTC as soon as possible • Save 3 things: UTC timestamp, UTC offset and time zone • Without UTC offset, you might break future times • Without time zone, you can't do calculations on the date • Convert back into local time when you display it
• Don't make false assumptions about time • Consider the purpose (e.g. reminder to buy festival vs. flight tickets) • Relative time is easy, recurring stuff is hard • Make sure your users don't get lost ❤