@Mikel -- if you *don't* set config.time_zone, ActiveRecord.default_timezone will work as expected -- you'll send values to the db in system local time, and times returned from the db will be returned as Time.local instances. When you do set config.time_zone, it sets ActiveRecord.default_timezone to :utc behind the scenes; but if you explicitly set AR.default_timezone to :local in combination with config.time_zone, things won't work correctly. This is the combination we're looking to fix, so that legacy apps can take advantage of the new time zone features.
@Nate -- thanks for following up on this -- correct, this functionality has yet to be added. I'm now thinking the way to go with this is, instead of putting logic into TimeWithZone#to_s(:db), we should modify ActiveRecord::AttributeMethods.define_write_method_for_time_zone_conversion so that, if AR.default_timezone is :local, it coerces the time object with #getlocal instead of #in_time_zone. With this setup, default_timezone will be respected on a per-model basis, as opposed to just a global setting. Let me know if you need help pulling this together, or have different ideas on how this could be implemented. On Oct 14, 3:18 am, "Mikel Lindsaar" <[EMAIL PROTECTED]> wrote: > On Tue, Oct 14, 2008 at 11:54 AM, Nate Wiger <[EMAIL PROTECTED]> wrote: > >> Actually, we're very close to having this working -- we'd just need to > >> tweak TimeWithZone#to_s(:db) to report the time relative to the system > >> local zone if config.active_record.default_timezone == :local. > > Unless I am missing something here... > > Wouldn't the time you store in the database be the timezone you set in > the config file? > > If I set config.active_record_default_timezone == :local, then all the > records in the database should be saved in my local time. > > Makes little difference with a timestamp with timezone, but all the > difference in the world on a record that is timestamp without, > especially when you are having to play good database citizen and share > the DB with other applications in other time zones that already save > everything in LA USA time because it is a 15 year old application / > convention :) > > anyway, the setting in the config file should over ride any default > value that the adapter thinks IMHO. This would be expected behaviour. > Not convert on the fly and _always_ store UTC in the DB regardless of > any config setting. This would cause serious problems for legacy DB > people I think. > > Mikel > > --http://lindsaar.net/ > Rails, RSpec and Life blog.... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---