diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 1d24ee5933..ea9249e24c 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,8 @@ *SVN* +* Added Base.default_timezone accessor that determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates + and times from the database. This is set to :local by default. + * Added the possibility for adapters to overwrite add_limit! to implement a different limiting scheme than "LIMIT X" used by MySQL, PostgreSQL, and SQLite. * Fixed that the const_missing autoload assumes the requested constant is set by require_association and calls const_get to retrieve it. diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ce10f03789..12f39c6985 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -221,6 +221,11 @@ module ActiveRecord #:nodoc: cattr_accessor :pluralize_table_names @@pluralize_table_names = true + # Determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database. + # This is set to :local by default. + cattr_accessor :default_timezone + @@default_timezone = :local + # When turned on (which is default), all associations are included using "load". This mean that any change is instant in cached # environments like mod_ruby or FastCGI. When set to false, "require" is used, which is faster but requires server restart to # reflect changes. diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 1ca6d59977..454fe98e7f 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -220,21 +220,21 @@ module ActiveRecord return string if Time === string time_array = ParseDate.parsedate(string).compact # treat 0000-00-00 00:00:00 as nil - Time.local(*time_array) rescue nil + Time.send(Base.default_timezone, *time_array) rescue nil end - def string_to_dummy_time(string) - return string if Time === string - time_array = ParseDate.parsedate(string) - # pad the resulting array with dummy date information - time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1; - Time.local(*time_array) rescue nil - end - + def string_to_dummy_time(string) + return string if Time === string + time_array = ParseDate.parsedate(string) + # pad the resulting array with dummy date information + time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1; + Time.send(Base.default_timezone, *time_array) rescue nil + end + def extract_limit(sql_type) $1.to_i if sql_type =~ /\((.*)\)/ end - + def simplified_type(field_type) case field_type when /int/i diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index c2a105f85d..8bbf98555d 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -327,7 +327,16 @@ class BasicsTest < Test::Unit::TestCase assert_equal 1, topic.approved assert_nil topic.last_read end - + + def test_utc_as_time_zone + Topic.default_timezone = :utc + attributes = { "bonus_time" => "5:42:00AM" } + topic = Topic.find(1) + topic.attributes = attributes + assert_equal Time.utc(2000, 1, 1, 5, 42, 0), topic.bonus_time + Topic.default_timezone = :local + end + def test_default_values_on_empty_strings topic = Topic.new topic.approved = nil