With Ruby 1.8.7:
>> require 'time'
>> Time.parse '01/28/2012'
=> Sat Jan 28 00:00:00 +0200 2012
>> Time.parse '28/01/2012'
=> ArgumentError: argument out of range
With Ruby 1.9.3:
>> require 'time'
>> Time.parse '28/01/2012'
=> 2012-01-28 00:00:00 +0200
>> Time.parse '01/28/2012'
=> ArgumentError: argument out of range
It looks like in Ruby 1.8.7 it was accepting US format (month/day/year), while in Ruby 1.9.3 it accepts only non US format (day/month/year).
Is there a way to change this behavior to be like Ruby 1.8.7?
Would it be an option for you to use
Time.strptime("01/28/2012", "%m/%d/%Y")in place ofTime.parse? That way you have better control over how Ruby is going to parse the date.If not there are gems: (e.g. ruby-american_date) to make the Ruby 1.9 Time.parse behave like Ruby 1.8.7, but only use it if it’s absolutely necessary.