1
0
Fork 0
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:
David Heinemeier Hansson 2004-12-28 17:30:17 +00:00
parent 8a9b998b79
commit 60de8c1108
4 changed files with 28 additions and 11 deletions

View file

@ -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.

View file

@ -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.

View file

@ -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

View file

@ -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