Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Base.default_timezone

#5679

When I start a server or console the default_timezone is :utc when should be :local

In the ActiveRecord::Base it's set to :local but in the railte it's set to :utc

rails/activerecord/lib/active_record/railtie.rb:38

35: initializer "active_record.initialize_timezone" do
36: ActiveSupport.on_load(:active_record) do
37: self.time_zone_aware_attributes = true
38: self.default_timezone = :utc
39: end
40: end

Reported by Marcio Trindade · September 22nd, 2010 @ 04:52 AM

State: invalid
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. José Valim
    José Valim
    • State changed from new to invalid
    • Importance changed from to Low

    The default should be :utc. You can change it in your config/application.rb by doing: "config.active_record.default_timezone = :local". Thanks.

    September 22nd, 2010 @ 08:53 AM

  2. Akira Matsuda
    Akira Matsuda

    Well, I suppose Marcio is not asking how to change the setting but pointing out the fact that AR and railties are setting different values for the same property.

    If the default should be :utc, then it should not be defaulted to :local in AR::Base.
    Here's a patch.

    December 16th, 2010 @ 08:02 AM

  3. Akira Matsuda
  4. Akira Matsuda
    Akira Matsuda
    • Tag changed from activerecord rails3, timezone to activerecord rails3, patch, tested, timezone

    December 16th, 2010 @ 09:56 AM

  5. José Valim
    José Valim
    • State changed from invalid to open

    I am sorry about misunderstanding the original issue.

    February 1st, 2011 @ 06:02 PM

  6. José Valim
    José Valim

    Although, I am not completely sure about the default here. Rails applications must default to :utc, but somehow AR defaults to :local? So I see why people are confused, but I don't think we can change the values today. Change the Railtie to local will break existing Rails applications, and changing AR will break AR usage outside Rails.

    February 1st, 2011 @ 06:05 PM

  7. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to invalid

    February 1st, 2011 @ 07:46 PM

  8. Akira Matsuda
    Akira Matsuda

    @José

    OK, I support your decision at this moment, but we should keep this trivial inconsistency in mind.

    I actually hit this problem when I was writing a tiny sample script using AR off Rails that connects to an existing Rails DB.
    You know what was happening, the DB shows different values from what I see in the Rails app (by default)!

    So, I hope this confusion to be fixed at some future release such as 4.0 (or 3.1?).

    February 1st, 2011 @ 11:13 PM

  9. José Valim
    José Valim

    So maybe we could set the value in AR to nil and when it is used for the first time, we could show a message like: "No value was chosen as ActiveRecord::Base.default_timezone, using :local as default. Please set to :local or :utc accordingly." What do you think? We could ship this in 3.1 and finally fix it on 3.2 or 4.0.

    February 1st, 2011 @ 11:17 PM

  10. af001
    af001

    私の中で、総合評価のとっても低いアバアバクロホリスタークロ銀座店。アバクロは大好きなんですけどね。一昨日の東京駅付近での打ち合わせの後、散歩がてら久々に行ってきました。そしたらビックリ!相変わらアバクロず、踊っているだけの店員さんとかもいましたが、

    May 5th, 2011 @ 03:00 AM