From 0daa29ece29191b288fe86d3616bea0357325419 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 1 Dec 2004 13:18:51 +0000 Subject: Added proper handling of time fields that are turned into Time objects with the dummy date of 2000/1/1 [HariSeldon] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@40 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../active_record/connection_adapters/abstract_adapter.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 4689ac3ac3..301ee208a3 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -182,6 +182,7 @@ module ActiveRecord when :float then Float when :datetime then Time when :date then Date + when :time then Time when :text, :string then String when :boolean then Object end @@ -195,6 +196,7 @@ module ActiveRecord when :integer then value.to_i when :float then value.to_f when :datetime then string_to_time(value) + when :time then string_to_dummy_time(value) when :date then string_to_date(value) when :boolean then (value == "t" or value == true ? true : false) else value @@ -220,6 +222,14 @@ module ActiveRecord 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.local(*time_array) rescue nil + end + def extract_limit(sql_type) $1.to_i if sql_type =~ /\((.*)\)/ end @@ -230,8 +240,10 @@ module ActiveRecord :integer when /float|double|decimal|numeric/i :float - when /time/i + when /datetime/i :datetime + when /time/i + :time when /date/i :date when /(c|b)lob/i, /text/i -- cgit v1.2.3