I would expect this code to give me an ArgumentError: invalid date
error. In Ruby 2.0.0 irb:
irb(main):003:0> Date.strptime('05-10-2014', '%Y-%m-%d')
=> #<Date: 0005-10-20 ((1723177j,0s,0n),+0s,2299161j)>
Am I doing something wrong or will Ruby accept a 2-digit year even when I specify %Y
?
I am looking at testing user input. In this case my program is expecting it in the %Y-%m-%d
and the input date was "entered" in the wrong format, but strptime
says it's ok.
There was a Ruby bug opened for this issue last year, but it was rejected. I guess the Ruby team feels that this is valid behavior.
https://bugs.ruby-lang.org/issues/8941
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With