Rails date conversion

The environment.rb file in a Rails 2.3.2 app says:

Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.

Auto-convert to this zone… when?

Also, what are the differences between these two statements?

config.time_zone = xxx
config.active_record.default_timezone = xxx

I ask these questions because I have a scenario whereby an AR-backed
object, when issued the “published_at” method yields a date like “Tue
Jul 28 17:04:58 UTC 2009”. However, when finding the object, e.g.
Object.first, I get what looks like a UTC date: “2009-07-28 17:07:11”.
(That is, when you find an object in console it shows you all its
attributes, and it is in there that I have what I think is a UTC date.)

So… what’s the deal?

On Jul 28, 1:28 pm, Daniel W. [email protected]
wrote:

I ask these questions because I have a scenario whereby an AR-backed
object, when issued the “published_at” method yields a date like “Tue
Jul 28 17:04:58 UTC 2009”. However, when finding the object, e.g.
Object.first, I get what looks like a UTC date: “2009-07-28 17:07:11”.
(That is, when you find an object in console it shows you all its
attributes, and it is in there that I have what I think is a UTC date.)

So… what’s the deal?

See:
http://ryandaigle.com/articles/2008/1/25/what-s-new-in-edge-rails-easier-timezones

Essentially, times recorded in the database by AR are now always in
UTC. The default time_zone is used to convert the DB values from UTC
for local display. The default TZ can be dynamically overridden in
the application to permit individual users to have times displayed in
their own locale TZ.

HTH

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs