Ruby on Rails Wednesday, August 21, 2013

On Tue, Aug 20, 2013 at 1:06 PM, Philip Edelbrock <phil@edgedesign.us> wrote:

> o Time.parse and Date.parse interprets slashed numerical dates·
>      as "dd/mm/yyyy".
>

Well, back to basics, my question is simple:

How do I tell Rails to use a custom date/time format without it blowing up?

I put this in an initializer:

Date::DATE_FORMATS.merge!(:default => '%m/%d/%Y')

See my previous comment; that format IS NOT VALID in Ruby 1.9.x and 
above. Your issue has nothing to do with Rails.
 
A simple way to manifest the problem is to do "Time.now.to_s.to_time" or "Date.today.to_s.to_date".  This works on Rails 2.3/Ruby 1.8.7, but does not on Rails 4.0/Ruby 2.0 with the above initializers.

It works fine with VALID formats. Change your initializer to '%d/%m/%Y'
and try `Date.today.to_s.to_date`  -- no problem.

It is hard to believe that they removed such basic functionality?  Tamara suggests this might be a Ruby bug(?).

No. It is documented behavior of Ruby.
 
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yB%2Bfeix-JnMop8DJ6u2Yhg2iDF%3DOmdhjxE8%2B%3Dkvm-RqZw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment