Here is the following from my console:>> Time.now=> Mon Sep 22 11:33:34 +0200 2008>> Time.now.utc_offset=> 7200>> TimeZone[Time.now.utc_offset]=> #<TimeZone:0x11aea90 @tzinfo=nil, @utc_offset=7200, @name="Athens">>> Time.now.in_time_zone(TimeZone[Time.now.utc_offset])=> Mon, 22 Sep 2008 12:34:22 EEST +03:00 (I am in Spain - CET - and running on OS X with the correct timezone) The Time.now correctly gives me the time, and the correct UTC offset of 2 hours. It is the summer, so we are 2 hours ahead of UTC. We are still one hour ahead of London, but London itself is an hour ahead as they too switch to a summer time (BST). ruby tells me that my utc_offset is 7200 - which is correct. But... when I pull out the timezone it gives me the wrong one. Athens is 3 hours ahead of UTC, not 2 (at this time of year). So, when I convert a time using the timezone it gives me it is an hour out! I had hoped that time zone woes were behind me after switching to RoR from Java. But it still seems to be a problem. How can I get the correct Time Zone? There is a bug tracked (http://dev.rubyonrails.org/ticket/4551) but it seems to be set to closed... but it definitely isn''t fixed! Right now I am doing this: offset = Time.now.dst? ? 60 : 0 Anyone have any better solutions? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Time.zone will give you the time zone currently set in Rails 2.1 You should set the time zone of your environment in the environment.db: config.time_zone = ''Amsterdam'' You can ask the users of your application to select their time zone (that''s something they''ll have to tell you, it''s not possible for Rails to guess :-)), save it in the user table as time_zone variable and set it for your current user in a before_filter: Time.zone @current_user.time_zone. More details are found here: http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ On 22 sep, 11:45, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote:> Here is the following from my console: > > >> Time.now > > => Mon Sep 22 11:33:34 +0200 2008>> Time.now.utc_offset > => 7200 > >> TimeZone[Time.now.utc_offset] > > => #<TimeZone:0x11aea90 @tzinfo=nil, @utc_offset=7200, @name="Athens">>> Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > > => Mon, 22 Sep 2008 12:34:22 EEST +03:00 > > (I am in Spain - CET - and running on OS X with the correct timezone) > > The Time.now correctly gives me the time, and the correct UTC offset > of 2 hours. It is the summer, so we are 2 hours ahead of UTC. We are > still one hour ahead of London, but London itself is an hour ahead as > they too switch to a summer time (BST). > > ruby tells me that my utc_offset is 7200 - which is correct. But... > when I pull out the timezone it gives me the wrong one. Athens is 3 > hours ahead of UTC, not 2 (at this time of year). So, when I convert a > time using the timezone it gives me it is an hour out! > > I had hoped that time zone woes were behind me after switching to RoR > from Java. But it still seems to be a problem. > > How can I get the correct Time Zone? > > There is a bug tracked (http://dev.rubyonrails.org/ticket/4551) but it > seems to be set to closed... but it definitely isn''t fixed! > > Right now I am doing this: > > offset = Time.now.dst? ? 60 : 0 > > Anyone have any better solutions?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Thanks for that, but it completely misses the point in that I can not even get the proper time zone conversion inside the server. I am not bringing a user''s timezone into the equation! I can''t go back and forth inside the same instance and get reliable results: Time.now and Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) should give me the same times back! it doesn''t. Anyway, I think I found another bug listed for this, so I will trust that someone more clever than I will figure it out. On Sep 22, 2:24 pm, deegee <dirkgro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Time.zone will give you the time zone currently set in Rails 2.1 > > You should set the time zone of your environment in the > environment.db: > config.time_zone = ''Amsterdam'' > > You can ask the users of your application to select their time zone > (that''s something they''ll have to tell you, it''s not possible for > Rails to guess :-)), save it in the user table as time_zone variable > and set it for your current user in a before_filter: Time.zone > @current_user.time_zone. > > More details are found here:http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ > > On 22 sep, 11:45, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > Here is the following from my console: > > > >> Time.now > > > => Mon Sep 22 11:33:34 +0200 2008>> Time.now.utc_offset > > => 7200 > > >> TimeZone[Time.now.utc_offset] > > > => #<TimeZone:0x11aea90 @tzinfo=nil, @utc_offset=7200, @name="Athens">>> Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > > > => Mon, 22 Sep 2008 12:34:22 EEST +03:00 > > > (I am in Spain - CET - and running on OS X with the correct timezone) > > > The Time.now correctly gives me the time, and the correct UTC offset > > of 2 hours. It is the summer, so we are 2 hours ahead of UTC. We are > > still one hour ahead of London, but London itself is an hour ahead as > > they too switch to a summer time (BST). > > > ruby tells me that my utc_offset is 7200 - which is correct. But... > > when I pull out the timezone it gives me the wrong one. Athens is 3 > > hours ahead of UTC, not 2 (at this time of year). So, when I convert a > > time using the timezone it gives me it is an hour out! > > > I had hoped that time zone woes were behind me after switching to RoR > > from Java. But it still seems to be a problem. > > > How can I get the correct Time Zone? > > > There is a bug tracked (http://dev.rubyonrails.org/ticket/4551) but it > > seems to be set to closed... but it definitely isn''t fixed! > > > Right now I am doing this: > > > offset = Time.now.dst? ? 60 : 0 > > > Anyone have any better solutions?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
phil wrote:> Time.now and Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > should give me the same times back! it doesn''t. >It looks like its working for me. I''m on Rails 2.1.1 on Mac OS X 10.5.5: Loading development environment (Rails 2.1.1)>> Time.now=> Tue Sep 23 11:13:02 -0500 2008>> Time.now.utc_offset=> -18000>> Time.now.in_time_zone(TimeZone[Time.now.utc_offset])=> Tue, 23 Sep 2008 11:13:28 COT -05:00>> TimeZone[Time.now.utc_offset]=> #<ActiveSupport::TimeZone:0x5cb1b0 @utc_offset=-18000, @name="Bogota", @tzinfo=#<TZInfo::DataTimezone: America/Bogota Although the TimeZone[Time.now.utc_offset] line didn''t return the correct time zone for me, as I''m in Central (US & Canada). Peace. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok phil, I see the point you''re trying to make. The thing I was trying to say is that it''s just not possible for Rails to really know in which time zone you are. So when you call TimeZone[some_offset], it can only make a guess about the time zone, because it doesn''t know if you''re in a time zone with or without DST. Again, in Rails 2.1, you should set your time zone via the config.time_zone command so that Rails knows in which time zone is your server. And you retrieve your time zone (that was your question, right?) using Time.zone So not using TimeZone.[] class method. On 23 sep, 00:40, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > Thanks for that, but it completely misses the point in that I can not > even get the proper time zone conversion inside the server. > I am not bringing a user''s timezone into the equation! > > I can''t go back and forth inside the same instance and get reliable > results: > Time.now and Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > should give me the same times back! it doesn''t. > > Anyway, I think I found another bug listed for this, so I will trust > that someone more clever than I will figure it out. > > On Sep 22, 2:24 pm, deegee <dirkgro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Time.zone will give you the time zone currently set in Rails 2.1 > > > You should set the time zone of your environment in the > > environment.db: > > config.time_zone = ''Amsterdam'' > > > You can ask the users of your application to select their time zone > > (that''s something they''ll have to tell you, it''s not possible for > > Rails to guess :-)), save it in the user table as time_zone variable > > and set it for your current user in a before_filter: Time.zone > > @current_user.time_zone. > > > More details are found here:http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ > > > On 22 sep, 11:45, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > > Here is the following from my console: > > > > >> Time.now > > > > => Mon Sep 22 11:33:34 +0200 2008>> Time.now.utc_offset > > > => 7200 > > > >> TimeZone[Time.now.utc_offset] > > > > => #<TimeZone:0x11aea90 @tzinfo=nil, @utc_offset=7200, @name="Athens">>> Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > > > > => Mon, 22 Sep 2008 12:34:22 EEST +03:00 > > > > (I am in Spain - CET - and running on OS X with the correct timezone) > > > > The Time.now correctly gives me the time, and the correct UTC offset > > > of 2 hours. It is the summer, so we are 2 hours ahead of UTC. We are > > > still one hour ahead of London, but London itself is an hour ahead as > > > they too switch to a summer time (BST). > > > > ruby tells me that my utc_offset is 7200 - which is correct. But... > > > when I pull out the timezone it gives me the wrong one. Athens is 3 > > > hours ahead of UTC, not 2 (at this time of year). So, when I convert a > > > time using the timezone it gives me it is an hour out! > > > > I had hoped that time zone woes were behind me after switching to RoR > > > from Java. But it still seems to be a problem. > > > > How can I get the correct Time Zone? > > > > There is a bug tracked (http://dev.rubyonrails.org/ticket/4551) but it > > > seems to be set to closed... but it definitely isn''t fixed! > > > > Right now I am doing this: > > > > offset = Time.now.dst? ? 60 : 0 > > > > Anyone have any better solutions?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Interesting... I am going to guess that you are not in a place that uses daylight savings time? On Sep 23, 6:15 pm, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> phil wrote: > > Time.now and Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > > should give me the same times back! it doesn''t. > > It looks like its working for me. I''m on Rails 2.1.1 on Mac OS X 10.5.5: > > Loading development environment (Rails 2.1.1)>> Time.now > > => Tue Sep 23 11:13:02 -0500 2008>> Time.now.utc_offset > => -18000 > >> Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > > => Tue, 23 Sep 2008 11:13:28 COT -05:00>> TimeZone[Time.now.utc_offset] > > => #<ActiveSupport::TimeZone:0x5cb1b0 @utc_offset=-18000, > @name="Bogota", @tzinfo=#<TZInfo::DataTimezone: America/Bogota > > Although the TimeZone[Time.now.utc_offset] line didn''t return the > correct time zone for me, as I''m in Central (US & Canada). > > Peace. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, You are correct in that I should use Time.zone for server time, but I have a value coming from the client that is there offset to gmt (from a javascript call)... oh well! thanks though On Sep 24, 4:37 pm, deegee <dirkgro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok phil, I see the point you''re trying to make. > > The thing I was trying to say is that it''s just not possible for Rails > to really know in which time zone you are. So when you call > TimeZone[some_offset], it can only make a guess about the time zone, > because it doesn''t know if you''re in a time zone with or without DST. > > Again, in Rails 2.1, you should set your time zone via the > config.time_zone command so that Rails knows in which time zone is > your server. And you retrieve your time zone (that was your question, > right?) using > Time.zone > So not using TimeZone.[] class method. > > On 23 sep, 00:40, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > Hi, > > Thanks for that, but it completely misses the point in that I can not > > even get the proper time zone conversion inside the server. > > I am not bringing a user''s timezone into the equation! > > > I can''t go back and forth inside the same instance and get reliable > > results: > > Time.now and Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > > should give me the same times back! it doesn''t. > > > Anyway, I think I found another bug listed for this, so I will trust > > that someone more clever than I will figure it out. > > > On Sep 22, 2:24 pm, deegee <dirkgro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Time.zone will give you the time zone currently set in Rails 2.1 > > > > You should set the time zone of your environment in the > > > environment.db: > > > config.time_zone = ''Amsterdam'' > > > > You can ask the users of your application to select their time zone > > > (that''s something they''ll have to tell you, it''s not possible for > > > Rails to guess :-)), save it in the user table as time_zone variable > > > and set it for your current user in a before_filter: Time.zone > > > @current_user.time_zone. > > > > More details are found here:http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ > > > > On 22 sep, 11:45, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote: > > > > > Here is the following from my console: > > > > > >> Time.now > > > > > => Mon Sep 22 11:33:34 +0200 2008>> Time.now.utc_offset > > > > => 7200 > > > > >> TimeZone[Time.now.utc_offset] > > > > > => #<TimeZone:0x11aea90 @tzinfo=nil, @utc_offset=7200, @name="Athens">>> Time.now.in_time_zone(TimeZone[Time.now.utc_offset]) > > > > > => Mon, 22 Sep 2008 12:34:22 EEST +03:00 > > > > > (I am in Spain - CET - and running on OS X with the correct timezone) > > > > > The Time.now correctly gives me the time, and the correct UTC offset > > > > of 2 hours. It is the summer, so we are 2 hours ahead of UTC. We are > > > > still one hour ahead of London, but London itself is an hour ahead as > > > > they too switch to a summer time (BST). > > > > > ruby tells me that my utc_offset is 7200 - which is correct. But... > > > > when I pull out the timezone it gives me the wrong one. Athens is 3 > > > > hours ahead of UTC, not 2 (at this time of year). So, when I convert a > > > > time using the timezone it gives me it is an hour out! > > > > > I had hoped that time zone woes were behind me after switching to RoR > > > > from Java. But it still seems to be a problem. > > > > > How can I get the correct Time Zone? > > > > > There is a bug tracked (http://dev.rubyonrails.org/ticket/4551) but it > > > > seems to be set to closed... but it definitely isn''t fixed! > > > > > Right now I am doing this: > > > > > offset = Time.now.dst? ? 60 : 0 > > > > > Anyone have any better solutions?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
phil wrote:> Interesting... I am going to guess that you are not in a place that > uses daylight savings time? > > On Sep 23, 6:15 pm, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>No, I am in a place that uses DST. Peace. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
phil wrote:> Thanks, > You are correct in that I should use Time.zone for server time, but I > have a value coming from the client that is there offset to gmt (from > a javascript call)... oh well!Hello Phil, Having quite a similar problem. Any idea how could I get a TimeZone instance for a given offset with disabled DST? Did you solve your problem with the offset? Regards, KIR -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Possibly Parallel Threads
- Introduction & time_zone_select with mapped TimeZone question
- TimeWithZone seems in rails 2.3 seems broken...is this the correct behavior?
- Time zone mapping from TimeZone to TZInfo::Timezone
- Timezone ActiveRecord and Rails3
- TimeZone, TZInfo, daylight savings, and composed_of