aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2011-07-15 20:30:27 +0900
committerAkira Matsuda <ronnie@dio.jp>2011-07-15 21:19:23 +0900
commit9cd1f754d032e8db2415f9791061dc3813684c5e (patch)
treeada6df0f15c558c14d670ae250080e113ef20fcb /activerecord/lib/active_record
parentf88e9d83f13c7d29120696d7e568fae1efea67f4 (diff)
downloadrails-9cd1f754d032e8db2415f9791061dc3813684c5e.tar.gz
rails-9cd1f754d032e8db2415f9791061dc3813684c5e.tar.bz2
rails-9cd1f754d032e8db2415f9791061dc3813684c5e.zip
convert multiple Date parameters into a nil if any of its bits were blank
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/base.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index deff1c65ef..c2f725445e 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2026,15 +2026,18 @@ MSG
# If Date bits were not provided, error
raise "Missing Parameter" if [1,2,3].any?{|position| !values_hash_from_param.has_key?(position)}
max_position = extract_max_param_for_multiparameter_attributes(values_hash_from_param, 6)
+ # If Date bits were provided but blank, then return nil
+ return nil if (1..3).any? {|position| values_hash_from_param[position].blank?}
+
set_values = (1..max_position).collect{|position| values_hash_from_param[position] }
- # If Date bits were provided but blank, then default to 1
# If Time bits are not there, then default to 0
- [1,1,1,0,0,0].each_with_index{|v,i| set_values[i] = set_values[i].blank? ? v : set_values[i]}
+ (3..5).each {|i| set_values[i] = set_values[i].blank? ? 0 : set_values[i]}
instantiate_time_object(name, set_values)
end
def read_date_parameter_value(name, values_hash_from_param)
- set_values = (1..3).collect{|position| values_hash_from_param[position].blank? ? 1 : values_hash_from_param[position]}
+ return nil if (1..3).any? {|position| values_hash_from_param[position].blank?}
+ 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