This project is archived and is in readonly mode.

#5679 ✓invalid
Marcio Trindade

ActiveRecord::Base.default_timezone

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

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

Comments and changes to this ticket

  • José Valim

    José Valim September 22nd, 2010 @ 08:53 AM

    • 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.

  • Akira Matsuda

    Akira Matsuda December 16th, 2010 @ 08:02 AM

    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.

  • Akira Matsuda
  • Akira Matsuda

    Akira Matsuda December 16th, 2010 @ 09:56 AM

    • Tag changed from activerecord rails3, timezone to activerecord rails3, patch, tested, timezone
  • José Valim

    José Valim February 1st, 2011 @ 06:02 PM

    • State changed from “invalid” to “open”

    I am sorry about misunderstanding the original issue.

  • José Valim

    José Valim February 1st, 2011 @ 06:05 PM

    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.

  • Santiago Pastorino

    Santiago Pastorino February 1st, 2011 @ 07:46 PM

    • State changed from “open” to “invalid”
  • Akira Matsuda

    Akira Matsuda February 1st, 2011 @ 11:13 PM

    @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?).

  • José Valim

    José Valim February 1st, 2011 @ 11:17 PM

    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.

  • af001

    af001 May 5th, 2011 @ 03:00 AM

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

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages