[ruby-core:96581] [Ruby master Bug#16440] Date range inclusion behaviors are inconsistent

[email protected] Sun, 29 Dec 2019 19:10:58 +0000 (UTC)
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83546.20191229191058.e560e6034c517e2a@ruby-lang.org>
Issue #16440 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Rejected

As explained in some previous comments, if you want to check if a value is on or after the beginning of the range and on or before the end of the range, use `cover?`.  `include?` should only be used if you want to check the argument is one of the members of the range (i.e. included in the array returned by `to_a`).

----------------------------------------
Bug #16440: Date range inclusion behaviors are inconsistent
https://bugs.ruby-lang.org/issues/16440#change-83546

* Author: st0012 (Stan Lo)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
It's weird that a Date range can include Time and DateTime objects that were converted from a Date object. But it can't include a newly generated DateTime object. For example:

```
may1 = Date.parse("2019-05-01")
may3 = Date.parse("2019-05-03")
noon_of_may3 = DateTime.parse("2019-05-03 12:00")
may31 = Date.parse("2019-05-31")

(may1..may31).include? may3 # => True
(may1..may31).include? may3.to_time # => True
(may1..may31).include? may3.to_datetime # => True
(may1..may31).include? noon_of_may3 # => False
```

Shouldn't the last case return `true` as well? 

Related Rails issue: https://github.com/rails/rails/issues/36175



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>