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?

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 Mad Mimi Email Marketing 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:

Ryan Bates has a good Railscast on timezones