Is there a way in 2.1 to compare Time Zones? Basically, my application''s time zone is set to EST. I have a Client model with a time zone and I have a drop down using TimeZone.us_zones which only stores the string of the time zone in the database. Is there a way however to compare (not <=>) the Time.zone.name with Client.timezone to get the offset difference? Greatly appreciated, Tim K. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
To follow up, I don''t think it''s an offset that I''m looking for. I want to be able to display the current datetime of a Client without altering the application''s time zone and basically show a "Time where they are" function on a client''s profile. Thanks, Tim K. On Jun 5, 12:54 am, blaine <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there a way in 2.1 to compare Time Zones? Basically, my > application''s time zone is set to EST. I have a Client model with a > time zone and I have a drop down using TimeZone.us_zones which only > stores the string of the time zone in the database. > > Is there a way however to compare (not <=>) the Time.zone.name with > Client.timezone to get the offset difference? > > Greatly appreciated, > > Tim K.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Why not just get the current time with the UTC, find the users timezone (stored in the database?) and then work it out from there? On Thu, Jun 5, 2008 at 2:29 PM, Tim K. <jangchub-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > To follow up, I don''t think it''s an offset that I''m looking for. I > want to be able to display the current datetime of a Client without > altering the application''s time zone and basically show a "Time where > they are" function on a client''s profile. > > Thanks, > > Tim K. > > On Jun 5, 12:54 am, blaine <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Is there a way in 2.1 to compare Time Zones? Basically, my > > application''s time zone is set to EST. I have a Client model with a > > time zone and I have a drop down using TimeZone.us_zones which only > > stores the string of the time zone in the database. > > > > Is there a way however to compare (not <=>) the Time.zone.name with > > Client.timezone to get the offset difference? > > > > Greatly appreciated, > > > > Tim K. > > >-- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Because I''m not sure how I can set the users time zone as an instance variable and have it behave like a time zone. All that is stored in the time zone name, for example, "Mountain Time (US & Canada)". Whether or not I''m getting the current time in UTC or not is irrelevant isn''t it? I mean essentially what I''m wanting to do (in poorly written 2am pseudo code) is something like: c = Client.find(1) c.timezone.now.to_s(:long) There c.timezone is returning the timezone name. I''m not really sure how to pull this off, that''s why I''m hoping someone can provide some guidance. I just want to know if it''s possible to now the current time of a timezone without have to reset the application''s timezone. On Jun 5, 1:59 am, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why not just get the current time with the UTC, find the users timezone > (stored in the database?) and then work it out from there? > > > > On Thu, Jun 5, 2008 at 2:29 PM, Tim K. <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > To follow up, I don''t think it''s an offset that I''m looking for. I > > want to be able to display the current datetime of a Client without > > altering the application''s time zone and basically show a "Time where > > they are" function on a client''s profile. > > > Thanks, > > > Tim K. > > > On Jun 5, 12:54 am, blaine <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Is there a way in 2.1 to compare Time Zones? Basically, my > > > application''s time zone is set to EST. I have a Client model with a > > > time zone and I have a drop down using TimeZone.us_zones which only > > > stores the string of the time zone in the database. > > > > Is there a way however to compare (not <=>) the Time.zone.name with > > > Client.timezone to get the offset difference? > > > > Greatly appreciated, > > > > Tim K. > > -- > Appreciated my help? > Recommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 5, 7:10 am, "Tim K." <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Because I''m not sure how I can set the users time zone as an instance > variable and have it behave like a time zone. All that is stored in > the time zone name, for example, "Mountain Time (US & Canada)". > Whether or not I''m getting the current time in UTC or not is > irrelevant isn''t it? I mean essentially what I''m wanting to do (in > poorly written 2am pseudo code) is something like: > > c = Client.find(1) > c.timezone.now.to_s(:long) > > There c.timezone is returning the timezone name. > > I''m not really sure how to pull this off, that''s why I''m hoping > someone can provide some guidance. I just want to know if it''s > possible to now the current time of a timezone without have to reset > the application''s timezone. >In rails 2.1 this is easy http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ Otherwise use something like the tzinfo_timezone, which lets you do something like tz = TzinfoTimezone.new(''London'') tz.utc_to_local(some_utc_time) Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok, I got it... I wasn''t looking at TimeZones as just another object. So basically to do what I was wanting it''s just something like this. c = Client.find(1) tz = TimeZone.new(c.timezone) tz.now Thanks :) On Jun 5, 5:32 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jun 5, 7:10 am, "Tim K." <jangc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Because I''m not sure how I can set the users time zone as an instance > > variable and have it behave like a time zone. All that is stored in > > the time zone name, for example, "Mountain Time (US & Canada)". > > Whether or not I''m getting the current time in UTC or not is > > irrelevant isn''t it? I mean essentially what I''m wanting to do (in > > poorly written 2am pseudo code) is something like: > > > c = Client.find(1) > > c.timezone.now.to_s(:long) > > > There c.timezone is returning the timezone name. > > > I''m not really sure how to pull this off, that''s why I''m hoping > > someone can provide some guidance. I just want to know if it''s > > possible to now the current time of a timezone without have to reset > > the application''s timezone. > > In rails 2.1 this is easyhttp://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/ > Otherwise use something like the tzinfo_timezone, which lets you do > something like > tz = TzinfoTimezone.new(''London'') > tz.utc_to_local(some_utc_time) > > Fred--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bates has a good Railscast on timezones http://railscasts.com/episodes/106 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---