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 Time.zone 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
offset.
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 (http://api.rubyonrails.org/classes/
ActiveSupport/TimeZone.html#M001511)
+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)
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.
I'm not thinking I will write a timezone library yet
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
users.
This is *very* frustrating.