Ruby on Rails Thursday, August 22, 2013

On Wed, Aug 21, 2013 at 8:55 PM, Phil <phil@edgedesign.us> wrote:

It's not a 'valid' vs. invalid argument

Of course it is. What you consider valid or not is irrelevant, it's defined in the language.

You happened to be lucky in picking a format (%m/%d/%Y) that worked in Ruby 1.8.7; 
the opposite day/month placement %d/%m/%Y doesn't:

1.8.7 :008 > Date.parse(Date.today.strftime('%m/%d/%Y')).to_s
 => "2013-08-22"
1.8.7 :009 > Date.parse(Date.today.strftime('%d/%m/%Y')).to_s
ArgumentError: invalid date
 
As Tamara suggests, it appears the format string is being dropped by the time it makes it to the parsing function(?). 

Date.parse doesn't take a format argument. The Rails String#to_date 
helper uses Date.parse. It "used to work" because you were lucky.

I can see an argument for replacing that with Date.strptime; why not
try it and see if anything breaks?  :-)

Add your use case to the tests and go for it. 

--
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/CACmC4yAuTqDhe4dgFbrdET7UYzujz71DEh-pX7yDMTH%2Bs18cPw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment