Permalink
Browse files

Rails::Initializer#initialize_time_zone raises an error if value assi…

…gned to config.time_zone is not recognized. Rake time zone tasks only require ActiveSupport instead of entire environment

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9104 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent d8823d6 commit 480a7581d4ec87eb745b004d6e4daae98b52cfa5 @gbuesing gbuesing committed Mar 28, 2008
Showing with 13 additions and 4 deletions.
  1. +2 −0 railties/CHANGELOG
  2. +7 −1 railties/lib/initializer.rb
  3. +4 −3 railties/lib/tasks/misc.rake
View
@@ -1,5 +1,7 @@
*SVN*
+* Rails::Initializer#initialize_time_zone raises an error if value assigned to config.time_zone is not recognized. Rake time zone tasks only require ActiveSupport instead of entire environment [Geoff Buesing]
+
* Stop adding the antiquated test/mocks/* directories and only add them to the path if they're still there for legacy reasons [DHH]
* Added that gems can now be plugins if they include rails/init.rb #11444 [jbarnette]
@@ -349,9 +349,15 @@ def initialize_temporary_session_directory
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
@@ -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

0 comments on commit 480a758

Please sign in to comment.