Rails transposing day and month after upgrading Ruby 1.8.7
June 26, 2013
If you’re wondering why your month and day are being transposed when saved in your database, you’re likely:
- Using American style date formatting (mm/dd/YYYY)
- Upgrading from Ruby 1.8.7
If you meet these criteria you’ll find that American style dates get parsed incorrectly in Ruby 1.9+ because of Ruby 1.9.x’s new date parsing strategy. Unbelievably, this change effectively does away with American style date parsing in Ruby 1.9.x and Rails has happily followed suit!
american_date to the rescue!
After trying and failing to restore American style date parsing using timeliness, delocalize, and i18n_alchemy, I found american_date. If you look at the implementation, it is straight forward and restores backwards compatibility by simply adding a line to your Gemfile. Enjoy the return to sanity!
With Ruby 1.8.7 going EOL this month, and Rails 2.3.x and older losing support for even sevre security issues, it’s time to bust out your upgrade-foo for those old Rails apps. Of course, this is a tried and true topic, with many resources, most notibly Railscast #225. Good luck with your upgrades!