airblade/paper_trail — pull request #331 by DaryMerckensGT (2014-02-21 06:43:03+00:00)
Title: PaperTrail.serializer#with_unformatted_dates_and_times to handle applica...

I was working on an application that had the following set:

Date::DATE_FORMATS[:default] = "%m/%d/%Y"

Now this is kind of on the YAML module, but I figured it would be more effective to implement a solution here. Basically the issue is that YAML doesn't properly load a dumped object with a formatted date attribute. For example:

[1] pry(main)> Date::DATE_FORMATS[:default] = "%m/%d/%Y"
=> "%m/%d/%Y"
[2] pry(main)> YAML.load({date: Date.today}.to_yaml)
=> {:date=>"02/21/2014"}
[3] pry(main)> Date::DATE_FORMATS[:default] = nil
=> nil
[4] pry(main)> YAML.load({date: Date.today}.to_yaml)
=> {:date=>Fri, 21 Feb 2014}

So it serializes the date as "02/21/2014", but can only parse dates in the form "2014-02-01".