The Challenges with Coding for Different Time Zones

Elizabeth Heil

Developers—the good ones, anyway—have a knack for making things look easy. What appears to be a simple button or drop-down menu to the user is actually a highly complex code base on the backend with fancy logic and formulas. A great example of a basic front end supported by a very robust backend is coding for time zones. We recently tackled time zones for a client when working on a calendar feature. We needed to account for how to display game times for an athletic tournament to users that live in a different time zone than where the game takes place. While we were “only” solving for time zones for one state and/or potentially a neighboring state or two, coding for international time zones presents a whole host of other challenges.

I recently came across another helpful (and humorous!) video from Computerphile that explains several of the hurdles you can run into when accounting for time zones. Below is a brief run down of what you’ll need to think about when building software that supports multiple time zones. Be sure to watch the video for even more fun facts!

Challenges with Coding for Time Zones

Non-traditional hourly differences between time zones: Typically we think of time zones in whole hour differences, e.g., 2 hours ahead or behind. However, there are some time zones that are not a whole hour, but rather 9 1/2 hours different, or 5 1/4 hours different. To account for this, be sure to include the full canonical list of ALL time zones.

Daylight Savings: Each country shifts to Daylights Savings on a different day. For example, Britain moves to Daylight Savings a week earlier. As if that wasn’t enough to factor in, there are also countries that move clocks in the opposite direction of what we do in the U.S. While we move our clocks back in the fall and forward in the spring, some others do the exact opposite, so forward in the fall and back in the spring.

Countries/states that change time zones: Some countries change time zones mid-year, and even multiple times a year. This may coincide with changes in government. Some countries decide to altogether cancel Daylight Savings. And then there are places like the West Bank (and the state of Indiana!) that have two populations of people in the same geographical location, but multiple time zones. It’s important to keep an updated file of all countries/states with known time zone changes.

Unix Time Stamp: This may be the most unique challenge of them all and was certainly never something I’ve given any thought to before learning about it in this video. Due to the Earth’s rotation at different speeds in a given year, we sometimes have to account for a “leap second”, which means there are 61 seconds in a minute versus the usual 60 seconds. Solving for this is some seriously fancy code work…

Time Zones can be a mind-bender for sure. Never underestimate the “gift” from those programmers who have solved this challenge before you and have made their code open source. Many thanks to all the developers that work so hard, and yet make it look so easy!