On Aug 20, 2013, at 7:57 AM, Hassan Schroeder <hassan.schroeder@gmail.com> wrote:
>
> In the source for e.g. ruby-1.9.3-p448 see ./doc/NEWS-1.9.1:
>
> 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')
Time::DATE_FORMATS.merge!(:default => '%m/%d/%Y %I:%M%p')
This is how I do that in Rails 2.3/Ruby 1.8.7, btw:
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(:default => '%m/%d/%Y')
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(:default => '%m/%d/%Y %I:%M%p')
That causes Rails 4.0/Ruby 2.0 to eat its self when dealing with forms that have dates/times. I'm not calling Date or Time directly in this case. I'm just letting Rails populate forms and then parse the params on submission to update a model. It is outputting the correct format, but it can't seem to parse what it is outputting. This wasn't a problem with Rails 2.3/Ruby 1.8.7.
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 is hard to believe that they removed such basic functionality? Tamara suggests this might be a Ruby bug(?).
Thanks!
Phil
--
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/EA644F48-1A1B-4DB1-A366-466690BA60E4%40edgedesign.us.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment