ruby / date

A subclass of Object includes Comparable module for handling dates.
Other
70 stars 35 forks source link

Strange behavior with invalid string date #18

Closed rbUUbr closed 4 years ago

rbUUbr commented 4 years ago

ruby version: 2.6.5 Code:

$ irb
require 'date'
puts  Date.parse('-1111-2-2').year # => -1111

expected behavior: ruby throws ArgumentError due to invalid string passed real behavior: negative year returns.

Is it ok?

jeremyevans commented 4 years ago

That's not an invalid date string, that's a perfectly valid date string for a negative year. Yes, it is OK and it is the expected behavior.

ioquatix commented 4 years ago

Ruby is designed with time travelling in mind.

https://www.youtube.com/watch?v=Qi7egXgYcgk