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 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) Thanks
I found this solution: http://spongetech.wordpress.com/2009/02/27/detecting-browser-time-zone-with-rails/#comment-725 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.
On Sep 23, 2009, at 7:41 AM, Florent wrote:> > I found this solution: http://spongetech.wordpress.com/2009/02/27/detecting-browser-time-zone-with-rails/#comment-725 > 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 Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
On Sep 23, 2:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> 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 > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.orgTrue. Officially hate timezones. I''m thinking about by-passing the Time.zone thing and implement a simple UTC + x conversion system. Am I going crazy?
2009/9/23 Florent <florentvaucelle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > > > On Sep 23, 2:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: >> 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 >> >> Rob Biedenharn http://agileconsultingllc.com >> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > True. Officially hate timezones. > > I''m thinking about by-passing the Time.zone 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. Colin
On Sep 23, 2009, at 9:11 AM, Florent wrote:> On Sep 23, 2:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: >> 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 >> >> Rob Biedenharn http://agileconsultingllc.com >> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > True. Officially hate timezones. > > I''m thinking about by-passing the Time.zone thing and implement a > simple UTC + x conversion system. > Am I going crazy?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. ;-) -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
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. Florent On 23 sep, 15:54, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Sep 23, 2009, at 9:11 AM, Florent wrote: > > > > > On Sep 23, 2:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > wrote: > >> 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 > > >> Rob Biedenharn http://agileconsultingllc.com > >> R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > > True. Officially hate timezones. > > > I''m thinking about by-passing the Time.zone thing and implement a > > simple UTC + x conversion system. > > Am I going crazy? > > 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. ;-) > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org