Fun with Timezones

(Everything you never wanted to know about timezones)


Jordi Boggiano
@seldaek

A Short History of Timezones



History

A long time ago Solar time / sundial

1675 Greenwich Mean Time at observatory for navigation

Early 1800s Clocks introduced, local mean solar time in every village

1847 Railway Time in UK (= GMT)

History

1855-1880 All British clocks on GMT, some had two hands

~1900-1930 GMT-based timezones normalization

1960 Coordinated Universal Time (UTC)

Properties of a Timezone

A day = One full rotation of the globe

A day = One full rotation of the globe



24 hours in a day = 24 timezones around the globe

Kind of...

Timezones are centered on the
Greenwich Observatory in London



0 = Greenwich Meridian Time = GMT = UTC



The rest spans from -12 to +12



Kind of...

Samoa UTC+13:00

Line Islands UTC+14:00

Timezones are 1h apart

Kind of...

Marquesas UTC-09:30

Nepal UTC+05:45

Iran UTC+03:30

Timezones never change

Kind of...

DST rules change quite often

Turkey switched in 2016 to permanent summer time +03:00

All changes recorded
in IANA tz database

Daylight Saving Time
DST
Summer Time

Energy savings

WWI / WWII during war time

1970s oil crisis

DST is NOT universal

DST switch happens at different date/time

Iceland is always using UTC

The timezone you are in
does not change

Europe/Rome stays Europe/Rome, but the offset goes from CET (+01:00) to CEST (+02:00)

Europe/London (i.e. UK) goes from GMT to BST in summer, BST = WEST = CET

UTC stays UTC in summer, like GMT. But GMT is a loaded term



Timezones and Programming

Most issues come from DST

DST switches at different dates



Knowing a timezone, you can't know the offset without a specific date, in a specific year



DST switching at midnight means ->modify('+1 day') can sometimes stay on the same date



Request user timezone based on location (i.e. Europe/Rome vs Europe/Zurich)

filter input, escape output

normalize input to UTC, format output to user timezone



All date logic in UTC => no DST, linear time



Thank you.

@seldaek

slides.seld.be

teamup.com