Comparing Time Zones

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.

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.

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. [email protected] wrote:

On Jun 5, 12:54 am, blaine [email protected] wrote:

Tim K.


Appreciated my help?
Recommend me on Working With Rails
http://workingwithrails.com/person/11030-ryan-bigg

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 B. (Radar)” [email protected]

On Jun 5, 7:10 am, “Tim K.” [email protected] wrote:

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

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

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 :slight_smile:

On Jun 5, 5:32 am, Frederick C. [email protected]

Ryan B. has a good Railscast on timezones