This project is archived and is in readonly mode.
ActiveRecord::Base.default_timezone
-
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.
-
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. -
Akira Matsuda
Failed to upload. Trying again...
-
Akira Matsuda
- Tag changed from activerecord rails3, timezone to activerecord rails3, patch, tested, timezone
-
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.
-
Santiago Pastorino
- State changed from open to invalid
-
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?).
-
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.
