diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/initializer.rb | 8 | ||||
-rw-r--r-- | railties/lib/tasks/misc.rake | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 4a536e0483..9909e6e45e 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -349,9 +349,15 @@ module Rails end end + # Sets the default value for Time.zone, and turns on ActiveRecord time_zone_aware_attributes. + # If assigned value cannot be matched to a TimeZone, an exception will be raised. def initialize_time_zone if configuration.time_zone - Time.zone_default = TimeZone[configuration.time_zone] + zone_default = TimeZone[configuration.time_zone] + unless zone_default + raise "Value assigned to config.time_zone not recognized. Run `rake -D time` for a list of tasks for finding appropriate time zone names." + end + Time.zone_default = zone_default if configuration.frameworks.include?(:active_record) ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.default_timezone = :utc diff --git a/railties/lib/tasks/misc.rake b/railties/lib/tasks/misc.rake index fcd860ae16..d083a8aef4 100644 --- a/railties/lib/tasks/misc.rake +++ b/railties/lib/tasks/misc.rake @@ -9,20 +9,21 @@ task :secret do puts Rails::SecretKeyGenerator.new(ENV['ID']).generate_secret end +require 'active_support' namespace :time do namespace :zones do desc 'Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' - task :all => :environment do + task :all do build_time_zone_list(:all) end desc 'Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' - task :us => :environment do + task :us do build_time_zone_list(:us_zones) end desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time' - task :local => :environment do + task :local do build_time_zone_list(:all, Time.now.beginning_of_year.utc_offset) end |