While updating a model with a datetime field, if
the datetime string is provided in a format that
DateTime#parse is not able to parse,
the field is just set to nil.
While calling DateTime#parse directly against that
string, an ArgumentError: invalid date exception is
thrown.
Setting through ActiveRecord:
ruby-1.9.2-p180 :001 > record = Production.where(:record_timestamp => nil).last
=> #<Production id: 175178, inverter_id: 13, created_at: "2011-03-11 17:59:16", updated_at: "2011-03-11 17:59:16", kwh_total: -1000.0, irradiance: 0.0, record_timestamp: nil, ambient_temp: nil>
ruby-1.9.2-p180 :002 > record.record_timestamp = '09/27/2010 22:26:49'
=> "09/27/2010 22:26:49"
ruby-1.9.2-p180 :003 > record.record_timestamp
=> nil
Using DateTime#parse:
ruby-1.9.2-p180 :004 > DateTime.parse '09/27/2010 22:26:49'
ArgumentError: invalid date
...