Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use cached column information to instantiate time object

  • Loading branch information...
commit 022d7b38468f1cb94f783ac402fdd167f6e027fe 1 parent ef52d34
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 6 additions and 6 deletions.
  1. +6 −6 activerecord/lib/active_record/attribute_assignment.rb
View
12 activerecord/lib/active_record/attribute_assignment.rb
@@ -179,8 +179,8 @@ def extract_callstack_for_multiparameter_attributes(pairs)
attributes
end
- def instantiate_time_object(name, values)
- if self.class.send(:create_time_zone_conversion_attribute?, name, column_for_attribute(name))
+ def instantiate_time_object(column, name, values)
+ if self.class.send(:create_time_zone_conversion_attribute?, name, column)
Time.zone.local(*values)
else
Time.time_with_datetime_fallback(self.class.default_timezone, *values)
@@ -195,7 +195,7 @@ def read_value_from_parameter(name, values_hash_from_param)
if klass == Time
read_time_parameter_value(column, name, values_hash_from_param)
elsif klass == Date
- read_date_parameter_value(name, values_hash_from_param)
+ read_date_parameter_value(column, name, values_hash_from_param)
else
read_other_parameter_value(klass, name, values_hash_from_param)
end
@@ -221,16 +221,16 @@ def read_time_parameter_value(column, name, values_hash_from_param)
set_values = (1..max_position).collect{ |position| values_hash_from_param[position] }
# If Time bits are not there, then default to 0
(3..5).each { |i| set_values[i] = set_values[i].blank? ? 0 : set_values[i] }
- instantiate_time_object(name, set_values)
+ instantiate_time_object(column, name, set_values)
end
- def read_date_parameter_value(name, values_hash_from_param)
+ def read_date_parameter_value(column, name, values_hash_from_param)
return if blank_date_parameter?(values_hash_from_param)
set_values = [values_hash_from_param[1], values_hash_from_param[2], values_hash_from_param[3]]
begin
Date.new(*set_values)
rescue ArgumentError # if Date.new raises an exception on an invalid date
- instantiate_time_object(name, set_values).to_date # we instantiate Time object and convert it back to a date thus using Time's logic in handling invalid dates
+ instantiate_time_object(column, name, set_values).to_date # we instantiate Time object and convert it back to a date thus using Time's logic in handling invalid dates
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.