Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimeZone vs Offset to store user timezone

I realize this is a commonly asked question but I couldn't find any posts that point out the disadvantages of using/storing offset for user's time zone. Is this not a better and more efficient way?

Long drop down lists of time zones are not user friendly and most of such lists don't have all the cities anyway. They also require user to specify their time zone. I feel it may be much better to simply detect it. In my case, my app is an ASP.NET Core app with Reach front end and it's pretty easy to capture user's time zone offset via JavaScript.

Any reason why storing the offset of user's timezone is NOT a good idea?

like image 295
Sam Avatar asked Oct 20 '17 17:10

Sam


1 Answers

Any reason why storing the offset of user's timezone is NOT a good idea?

Yes. Many. A time zone and an offset are not the same thing. A time zone represents a geographical area in which local time is aligned. A time zone may undergo several different changes in its offset from UTC. Some of which are regular (like daylight saving time), and some of which are irregular (like when a government changes its standard time or dst rules).

... In my case, I simply want to display all date time values in user’s current time zone so that they’re meaningful to the user.

Ok, so let's say you check the user's current time zone offset and it is UTC-7. So you apply that to some dates and times in your application and done - so you think. Except that you didn't take into account that the user is in California, and one of your dates is in December when the offset should be UTC-8.

So you try to correct for that, and work out the rules of "when I see -7, it might be -8 sometimes". Except now you have a user come along who is in Colorado, where it is -7 during the winter and -6 during the summer. Or another user from Arizona, where most of the state is in -7 for the whole year. How do you know which set of rules to follow? Without referencing an actual time zone, it cannot be done.

This gets even more complex worldwide. For example, the number of variations for UTC+2 is just crazy. Even for countries that switch between UTC+2 and UTC+3 - they don't all switch on the same dates or at the same time of day!

See also: The Problem with Time & Timezones - Computerphile (YouTube) and the StackOverflow timezone tag wiki.

like image 120
Matt Johnson-Pint Avatar answered Oct 09 '22 04:10

Matt Johnson-Pint