mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@271 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
8a9b998b79
commit
60de8c1108
4 changed files with 28 additions and 11 deletions
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -220,7 +220,7 @@ 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)
|
||||
|
@ -228,7 +228,7 @@ module ActiveRecord
|
|||
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
|
||||
Time.send(Base.default_timezone, *time_array) rescue nil
|
||||
end
|
||||
|
||||
def extract_limit(sql_type)
|
||||
|
|
|
@ -328,6 +328,15 @@ class BasicsTest < Test::Unit::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue