aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/initializer.rb16
2 files changed, 18 insertions, 0 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index e4a0a98d37..1e1f328837 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add config.time_zone for configuring the default Time.zone value. #10982 [Geoff Buesing]
+
* Reshuffle load order so that routes and observers are initialized after plugins and app initializers. Closes #10980 [rick]
* Git support for script/generate. #10690 [ssoroka]
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index 4e94b850d8..d839415e49 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -81,6 +81,7 @@ module Rails
initialize_dependency_mechanism
initialize_whiny_nils
initialize_temporary_session_directory
+ initialize_time_zone
initialize_framework_settings
add_support_load_paths
@@ -316,6 +317,16 @@ module Rails
end
end
+ def initialize_time_zone
+ if configuration.time_zone
+ Time.zone_default = TimeZone[configuration.time_zone]
+ if configuration.frameworks.include?(:active_record)
+ ActiveRecord::Base.time_zone_aware_attributes = true
+ ActiveRecord::Base.default_timezone = :utc
+ end
+ end
+ end
+
# Initializes framework-specific settings for each of the loaded frameworks
# (Configuration#frameworks). The available settings map to the accessors
# on each of the corresponding Base classes.
@@ -456,6 +467,11 @@ module Rails
end
alias_method :breakpoint_server=, :breakpoint_server
+ # Sets the default time_zone. Setting this will enable time_zone
+ # awareness for ActiveRecord models and set the ActiveRecord default
+ # timezone to :utc.
+ attr_accessor :time_zone
+
# Create a new Configuration instance, initialized with the default
# values.
def initialize