Why do Software Engineers need to consider more about time zones?

Oshan Vikasith
5 min readMar 12, 2022
Photo by Sigmund on Unsplash

In this article we are going to discuss how time zones affect software engineers. How to manage application development when time zones come into play. Hope you will be able to get an understanding of details with regards to time zones.

Time Zones

When the sun rises for one part of the planet, it sets in another part of the planet. This is due to the rotation of the Earth. Every country is placed in a specific time zone which was created by humans. Time zones were created to ensure that all countries had the same amount of time in relation to a day.

Figure 1: Display of way how sun rays falls on to earth (https://c.tadst.com/gfx/1200x630/september-equinox-dark.png?1)
  • Time differs from country to country and also location to location due to the implementation of time zones. On some occasions dates are also going to change, as software engineers we need to concern these core factors when developing a software solution.
  • The world is divided into time zones by longitude. Each longitude line is divided into fifteen degrees. Depending on which direction you travel, time travels forward or backwards one hour for every fifteen degrees of longitude.
  • All time zones are derived from the Greenwich Observatory in England as a starting point.
  • If we develop an application for a country which is in a different time zone and if we develop the application according to the local time zone then it would create chaos. So it is essential that we understand time zones as software engineers.
Figure 2: Time zones of the world (Time zone — Wikipedia)

UTC — Universal Time Coordinated

The major time standard by which the world governs clocks and time is Coordinated Universal Time, or UTC. This is a British time zone standard that is used to set all time zones around the world. Greenwich Mean Time (GMT) does not have a UTC offset value. The time in Sri Lanka can be obtained by adding 5 hours and 30 minutes to the UTC (UTC + 05:30).

Note

  • From UTC+12:00 to UTC+14:00, all time zones are defined as offsets from Coordinated Universal Time (UTC). In most cases, the offsets are a whole number of hours.
  • During the spring and summer, several places of higher latitude adopt daylight saving time for portions of the year, often by adding one hour to local time.
  • In the same country, different time zones can be present.
  • In two distinct countries, the time zone can be similar.

What is daylight Saving?

During the warmer months, daylight saving is the practice of advancing clocks (usually by one hour) so that darkness falls at a later clock time. Clocks are often set forward by one hour in the spring (“spring forward”) and to revert to standard time, turn backward by one hour in the autumn (“fall back”).

As a result, in late winter or early spring, there is one 23-hour day and, while in autumn, there is one 25-hour day.

The main purpose of daylight saving is to make better use of daylight.

Countries near the equator, on the other hand, do not follow this approach because dawn and sunset hours do not vary significantly near the equator over the seasonal changes.

How do software engineers deal with time zones when developing applications?

All programming languages have come up with solutions for these problems, in the early days of programming these were a bit confusing but nowadays libraries and packages are there to help when developing.

In order to overcome confusions, what we should do is when programming, if we have to save dates and time, we should convert the date and time to UTC time or we have to store the time zone information (offset value)other than saving it as local time. After converting the time we should store the date in the central server. If we save time according to the UTC format is very easy to trace back time according to the specific time zone. Then we can retrieve the data and convert according to the time zone. This should be followed as a practice when developing software's.

Eg -:

Assume my server is in Sri Lanka and the user is in London. As a result, when a user uses the app, he expects to see the clock in his own time zone. For sites where the client and server are in the same time zone, this may not be an issue. When the program displays the server time in Sri Lanka for a client in London, the problem will occur. So, what’s the best way to deal with such a problem?

Solution:

We can find the offset value associated with a specific location using a JavaScript API (getTimezoneOffset()). We can determine the time zone based on the location using the offset value, and then record it using a cookie. Finally, submit the information about the time zone to the central server. Now the central server must send the information for that specific time zone. The values must now be sent to the client after converting the time according to the offset (Time zone). When saving date and time information in the central server, we must be vigilant enough to set according to the UTC format.

You will be able to understand how date and time are managed in Java by reading the article below.

Introduction to Java Date & Time. In this article we are going to discuss… | by Oshan Vikasith | Mar, 2022 | Medium

Hope you had a better understanding regarding time zones, Hope to see you again in the future with another interesting article.

--

--