Converting a Time to a String and Back in Rails 4.0.0

This isn't a Rails problem, it's something that happens in Ruby. I think it's a bug:

$ irb -r date irb(main):001:0> format = "%m/%d/%Y" => "%m/%d/%Y" irb(main):002:0> Date.parse(Date.today.strftime(format),format) ArgumentError: invalid date   from (irb):2:in `parse'   from (irb):2   from /Users/tamara/.rubies/ruby-2.0.0-p427/bin/irb:12:in `<main>' irb(main):003:0> Date.today.strftime(format) => "08/18/2013" irb(main):004:0> Date.parse(Date.today.to_s) => #<Date: 2013-08-18 ((2456523j,0s,0n),+0s,2299161j)>

$ ruby -v ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]

I don't have anything older to check this on, however, reading the system documentation for strptime(), it seems to state that formats should be compatible with strftime().

A quick test in C[1] shows that the format from strftime to strptime is compatible. So sounds like a ruby bug…

Thanks! Yes, I did update to Ruby 2.0.0p247, but I also updated to Rails-4 and, well, entirely new hardware and OS as well, so I'm not sure where the bug is exactly.

I worked around it for now:

     params[:form][:time_field] = Time.strptime(params[:form][:time_field],"%m/%d/%Y %I:%M%p")      @myobj = MyObj.new(params[:form].permit!)

Phil