Korva
Tech

Do Not Hand-Code Time Zones, Keep the List Updated

Parts of Australia are 9 and a half hours ahead, and Nepal is 5 hours and 45 minutes ahead.

AI image
Computerphile · The Problem with Time & Timezones - Computerphile

Mike Pound, the speaker in a talk for programmers, starts with a simple app that counts seconds since a date. It adds a dropdown for how many whole hours ahead of Greenwich the user is, with Greenwich as the zero point the offsets are counted from.

Australia breaks it by being 9 and a half hours ahead, so the programmer adds a special case. Then Nepal breaks it further by being 5 hours and 45 minutes ahead, so the programmer adds another special case and maybe checks the standard list of zones that tells what everything is.

The list does not stay still. Countries change their zones fairly often, and the changes are usually announced ahead of schedule. But not always. Libya in 2013 gave just a few days of warning that it would not put the clocks back, and in the West Bank two populations in the same place follow different zones, which cannot be coded into the program.

Questions people ask

What is Greenwich in this context?

Greenwich is a district in London that holds the prime meridian, zero degrees longitude. Time zone offsets are counted as hours ahead of or behind time at Greenwich.