Set from offset including DST

Hi all,

I have a big deal with timezones: is it possible to set a user's
timezone from it's offset from UTC?
I mean, I don't want to ask the user in which timezone he is, so I get
this offset from a Javascript call
and set from this.

It worked until I noticed this problem:
In Paris, we are in UTC+2 in the summer, so I have a 7200 seconds
ActiveSupport::TimeZone will not return the Paris timezone, but the
first one it can get with a 7200 offset,
which is Athen. The trick is that Athen is currently (September) UTC
+3, so I'll getting fooled by TimeZone.

I saw this in the Rails API (
+TimeZone::new(name, utc_offset, tzinfo = nil) + but can't use it

What am I doing wrong/missing? (apart from not asking the user for his
timezone :p)


I found this solution:
Basically, it selects the good timezone by checking the a timezone is
currently in DST and by comparing the given offset with its own one.

This solution seems to work (have to make more tests) but feels bad.

It can't be foolproof because the northern and southern hemispheres have opposite seasons and when they observe daylight time is understandably about a half-year off from the other hemisphere. I'm sure (even without trying to check) that there are parts of each year where pairs of time zones are either both observing daylight time or not with the same UTC offset so the best that you could do was to offer a small set of possible zones.


Rob Biedenharn

True. Officially hate timezones.

I'm thinking about by-passing the thing and implement a
simple UTC + x conversion system.
Am I going crazy?

That is the inescapable result for all those who get too deeply
involved with timezone issues.


If you want to show a user a local time, you're going to have to deal with DST even if only to give the user a way to change the offset twice a year.

If you start to think that you should implement your own TimeZone library, then you might already be crazy. :wink:


Rob Biedenharn

I'm not thinking I will write a timezone library yet :wink:

Currently I get the user offset from Javascript (I know about non js-
enabled browsers), so I think about _maybe_ not using timezones at
all, but just the offset for displaying purpose. This would be the
last chance try.

For now, I think I'll make it with the "hack" in the comment I linked
in the second post.
This seems to be the most affordable "error seen/time spent" solution
out there, with the help of a setting if it doesn't work for some
This is *very* frustrating.