Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8839

Show
Ignore:
Timestamp:
02/10/08 01:10:43 (7 months ago)
Author:
nzkoz
Message:

2-0-stable: When multiparameter date assignment fails due to an invalid date, fall back to create a Time and convert to_date. References #10556 [leikind]

Merging [8777]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2-0-stable/activerecord/lib/active_record/base.rb

    r8585 r8839  
    23922392 
    23932393      # Includes an ugly hack for Time.local instead of Time.new because the latter is reserved by Time itself. 
     2394      def instantiate_time_object(*values) 
     2395        @@default_timezone == :utc ? Time.utc(*values) : Time.local(*values) 
     2396      end 
     2397 
    23942398      def execute_callstack_for_multiparameter_attributes(callstack) 
    23952399        errors = [] 
     
    24002404          else 
    24012405            begin 
    2402               send(name + "=", Time == klass ? (@@default_timezone == :utc ? klass.utc(*values) : klass.local(*values)) : klass.new(*values)) 
     2406              value = if Time == klass 
     2407                instantiate_time_object(*values) 
     2408              elsif Date == klass 
     2409                begin 
     2410                  Date.new(*values) 
     2411                rescue ArgumentError => ex # if Date.new raises an exception on an invalid date 
     2412                  instantiate_time_object(*values).to_date # we instantiate Time object and convert it back to a date thus using Time's logic in handling invalid dates 
     2413                end 
     2414              else 
     2415                klass.new(*values) 
     2416              end 
     2417 
     2418              send(name + "=", value) 
    24032419            rescue => ex 
    24042420              errors << AttributeAssignmentError.new("error on assignment #{values.inspect} to #{name}", ex, name)