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? -- Posted via http://www.ruby-forum.com/.
On Jul 28, 1:28 pm, Daniel Waite <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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
Reasonably Related Threads
- Some timezone trouble involving tzinfo and postgresql
- TimeZone, TZInfo, daylight savings, and composed_of
- config.default_timezone vs. config.time_zone
- ActiveRecord with different Date/Time format
- Introduction & time_zone_select with mapped TimeZone question