Bug #11984
closedDateTime.parse can parse invalid datetime string
Description
It seems if you pass a string which begins with 2 alphabets and following is 7 numerics, it can be parsed as DateTime, as follows
irb(main):002:0> require 'time'
irb(main):008:0> dt0 = DateTime.parse('fg4534253dd')
=> #<DateTime: 4534-09-10T00:00:00+00:00 ((3377322j,0s,0n),+0s,2299161j)>
irb(main):009:0> dt0 = DateTime.parse('fg4534253')
=> #<DateTime: 4534-09-10T00:00:00+00:00 ((3377322j,0s,0n),+0s,2299161j)>
irb(main):010:0> DateTime.parse('gg1233234')
=> #<DateTime: 1233-08-22T00:00:00+00:00 ((2171645j,0s,0n),+0s,2299161j)>
irb(main):011:0> DateTime.parse('gg1233234dd')
=> #<DateTime: 1233-08-22T00:00:00+00:00 ((2171645j,0s,0n),+0s,2299161j)>
Updated by long_long_float (kazuki niimi) about 6 years ago
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Status changed from Open to Rejected
This isn't a bug. DateTime.parse
assume the string you are passing in has some date related information in it, and tries the best it can to find something. In this case, it guesses that the first four digits are the year and the last three are the day of the year. The non-digits in this case are ignored.
DateTime._parse('fg4534253dd')
# => {:year=>4534, :yday=>253}
DateTime._parse('4534253')
# => {:year=>4534, :yday=>253}