From ce7cdb90728d2883e6eee100f3c6a845d3569d63 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Sun, 12 Aug 2012 20:26:17 +1000 Subject: Fix for time type columns with invalid time The string_to_dummy_time method was blindly parsing the dummy time string with Date._parse which returns a hash for the date part regardless of whether the time part is an invalid time string. --- activerecord/lib/active_record/connection_adapters/column.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 1445bb3b2f..d0237848c7 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -178,7 +178,13 @@ module ActiveRecord return string unless string.is_a?(String) return nil if string.blank? - string_to_time "2000-01-01 #{string}" + dummy_time_string = "2000-01-01 #{string}" + + fast_string_to_time(dummy_time_string) || begin + time_hash = Date._parse(dummy_time_string) + return nil if time_hash[:hour].nil? + new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction)) + end end # convert something to a boolean -- cgit v1.2.3