When something happened

This post is in response to many claims of other posts stating that storing a UTC date is not enough in all situations. The most recent one that triggered me being this one. They all claim that you lose information about when something happened. I will refer to Unix timestamps when saying timestamps from now on.

Unix timestamp

The Unix timestamp is defined as the amount of seconds since 01-01-1970 00:00:00.000 . This can also be turned into milliseconds for added precision. So currently that number is 1575818989 as of writing this post.

The argument

The argument I generally hear when only using timestamps is that you lose the timezone information and that thereby you lose vital information on when something happened. However whether or not you have the timezone information, the moment in UTC does not change. Taking a line from the article mentioned above:

It is the same moment, for everyone around the globe.

This is true for all date time representations. Regardless of timezone information the moment expressed in UTC is the same as the one with timezone information in it.

The timezone tells us what

The timezone tells us when it happened in that timezone. Which if we convert to UTC will be the same information. The timezone does not add any more information and the following statement made in aforementioned article: > A local date and time plus a UTC offset can be converted to a UTC date and time, but not the other way around. is not true. Anyone can give a timestamp to an object in the standard library and convert to a local date time based on any locale of your choosing. At best the timezone at time of request tells us where the request was made in a geographical area defined by that timezone. There is an argument on package delivery and it states we can convert to a timezone but to which one? The from the user or where the package is delivered to. How about both?

When vs where

Timestamps tells us when something happened and it is equal for all people across the globe regardless of timezone or Daylight Savings Time for that matter. The seconds keep on ticking since 1970-01-01 and it will not change based on political or geographical turmoil. If you want to know where something happened then it might be better to use a different format, like geolocation coordinates. So store the coordinates of where the user is and where the package will delivered to and you can show both time-zones.

The whole argument of aforementioned article stating it is important to save the timezone offset because in the future the European Union all need to choose one of the two either permanent Daylight Savings Time or not, therefore we know what it will be, is moot. If you store in timestamp format it will be the same moment regardless of what timezone offset is given. Just pass it along to the frontend or other backends and let them convert the timestamp to local date time representation and it will work in 2020 and, if we are still here, in 2220.

#devlife #thoughts