The programmers guide to timestamps and timezones

Shrayas Rajagopal (~shrayas)


1

Vote

Description:

Problem

There are 24 different timezones in the world. And about 70 countries observe daylight savings times. As developers, we have to develop applications that are able to store timestamps generated from anywhere in the world, be it in the past or in the future. Additionally we also have to keep the code and database updated with any changes being made to the timezones and react to those accordingly. And timezone information changes quite often. For example, in 2022, we had 7 changes to the timezone database.

Most of us when asked what timezone we are in, would respond with “IST” but you know that IST isn’t a standardized timezone and can actually refer to Indian Standard Time, Israel Standard Time or Irish Standard Time. How do we handle this in the system?

For countries that observe DST (daylight savings time), when the clocks move forward, an entire hour is usually skipped and when they move backward, an hour occurs twice. So on a move forward day, an appointment scheduled for 3:00PM might actually be an invalid time. And on a move backward day, an appointment scheduled for 3:00PM might occur twice. How do we handle this in the system?

One quick answer, given that all times in the world can be converted into UTC, would be to say “Let’s just store everything in UTC”. But there are problems in taking that approach too which we will discuss in the talk.

Jon Skeet, the author of the leading library to handle dates and times in the .NET world summarizes the date & time problem best by saying: “Either you don’t know it is difficult, or you know it is difficult but you assume that it is so difficult that you’ll never ever get the right answer so you will just be OK with getting things occasionally wrong”.

But there is one way by which we *can* tame the great date and time beasts - thorough understanding of the concepts.

We will start by looking at some of the most common questions that come up when dealing with parsing, storing and interacting with dates and times:

  • What are timezones?
  • What is daylight savings time?
  • How do I store timestamps in the database?
  • Why can’t I just store UTC everywhere?
  • How often do things change in the world?
  • Why is this so hard?

All these are very normal questions to ask. And they cause problems when not handled properly in production.

Another very subtle but important nuance for this conference is that we live in a country (India) which only has 1 timezone and where daylight savings isn’t observed. Hence, we have the privilege of having to never “change” our watches and clocks unless we go our of our country somewhere. So unless we have some prior experience with dealing with date and time in software systems, most of us (me included) start in the dark.

Building software however expects a clean understanding of dates and times and the associated nuances.

Outline of the talk

This session aims to address 3 key points:

  1. Introduce the audience to the concepts around time and date and timestamps
  2. Highlight the complexities that arise from storing timestamps
  3. Give practical advise on how to solve the complexities predictably in a production scenario

This talk aims to equip the audience with the concepts and knowledge they need to solve date and time problems in any environment / language they work in. There will also be code samples in Python to better illustrate the concepts.

Not in scope

This talk will *NOT* deal with the problems of the scientific / high precision computing world where ideas like leap seconds are important.

Prerequisites:

This talk is aimed at individuals who are beginners to the world of dates and times. The part about handling things in production will have information that will be of use to seniors to validate their approaches in systems they are responsible for as well.

Speaker Info:

My name is Shrayas and currently, I head the engineering efforts at a Logic Soft - a small organization with a large impact. Logic Soft is the only recognized software providers for the Book Trade businesses. If you have ever visited a popular book store anywhere in India, it is very likely that our software is running their business behind the scenes.

At Logic Soft I am responsible for all key technical and business decisions and have set a foundation for building the next generation of web and mobile applications in the organization. I enjoy building simple and future proof software with a focus on readability and scalability. I strongly believe that new technologies are not the right way to solve problems - simple & scalable design is.

Previously at SAP Labs, I worked on a small team that helped test and build out Sentinel - an Algorithmic Trading platform on a then new gen SAP database - SAP HANA

Outside of work, I enjoys running very long distances, trekking mountains or whipping up something in the kitchen. I used to be the co-coordinator for Chennaipy and have spoken many times at monthly meetups. I was also one of the core organizers of PySangamam and PyCon India 2019.

I write on shrayas.com occasionally.

Section: Web & App development
Type: Talks
Target Audience: Intermediate
Last Updated: