* [ruby-core:72837] [Ruby trunk - Bug #11984] [Open] DateTime.parse can parse invalid datetime string
[not found] <redmine.issue-11984.20160113054240@ruby-lang.org>
@ 2016-01-13 5:42 ` lanscene
2018-09-13 7:43 ` [ruby-core:88984] [Ruby trunk Bug#11984] " niinikazuki
2019-06-27 22:45 ` [ruby-core:93394] " merch-redmine
2 siblings, 0 replies; 3+ messages in thread
From: lanscene @ 2016-01-13 5:42 UTC (permalink / raw
To: ruby-core
Issue #11984 has been reported by jarry xu.
----------------------------------------
Bug #11984: DateTime.parse can parse invalid datetime string
https://bugs.ruby-lang.org/issues/11984
* Author: jarry xu
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux] and ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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)>
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:88984] [Ruby trunk Bug#11984] DateTime.parse can parse invalid datetime string
[not found] <redmine.issue-11984.20160113054240@ruby-lang.org>
2016-01-13 5:42 ` [ruby-core:72837] [Ruby trunk - Bug #11984] [Open] DateTime.parse can parse invalid datetime string lanscene
@ 2018-09-13 7:43 ` niinikazuki
2019-06-27 22:45 ` [ruby-core:93394] " merch-redmine
2 siblings, 0 replies; 3+ messages in thread
From: niinikazuki @ 2018-09-13 7:43 UTC (permalink / raw
To: ruby-core
Issue #11984 has been updated by long_long_float (kazuki niimi).
Is it a specification? When you pass 'fg4534253dd' to `DateTime#parse`, [`parse_ddd`](https://github.com/ruby/ruby/blob/480a21f435d2917190c087206bbffbd3d532824a/ext/date/date_parse.c#L1894) is called. It doesn't parse from begin of string.
And [document](https://ruby-doc.org/stdlib-2.5.1/libdoc/date/rdoc/DateTime.html#method-c-parse) says `DateTime#parse` is not for validator.
----------------------------------------
Bug #11984: DateTime.parse can parse invalid datetime string
https://bugs.ruby-lang.org/issues/11984#change-74013
* Author: lanscene (jarry xu)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux] and ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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)>
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:93394] [Ruby trunk Bug#11984] DateTime.parse can parse invalid datetime string
[not found] <redmine.issue-11984.20160113054240@ruby-lang.org>
2016-01-13 5:42 ` [ruby-core:72837] [Ruby trunk - Bug #11984] [Open] DateTime.parse can parse invalid datetime string lanscene
2018-09-13 7:43 ` [ruby-core:88984] [Ruby trunk Bug#11984] " niinikazuki
@ 2019-06-27 22:45 ` merch-redmine
2 siblings, 0 replies; 3+ messages in thread
From: merch-redmine @ 2019-06-27 22:45 UTC (permalink / raw
To: ruby-core
Issue #11984 has been updated by jeremyevans0 (Jeremy Evans).
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.
```ruby
DateTime._parse('fg4534253dd')
# => {:year=>4534, :yday=>253}
DateTime._parse('4534253')
# => {:year=>4534, :yday=>253}
```
----------------------------------------
Bug #11984: DateTime.parse can parse invalid datetime string
https://bugs.ruby-lang.org/issues/11984#change-78930
* Author: lanscene (jarry xu)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux] and ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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)>
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-06-27 22:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-11984.20160113054240@ruby-lang.org>
2016-01-13 5:42 ` [ruby-core:72837] [Ruby trunk - Bug #11984] [Open] DateTime.parse can parse invalid datetime string lanscene
2018-09-13 7:43 ` [ruby-core:88984] [Ruby trunk Bug#11984] " niinikazuki
2019-06-27 22:45 ` [ruby-core:93394] " merch-redmine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).