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

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83306.20191221035107.77546d1d571a33f9@ruby-lang.org>
Issue #16440 has been updated by shevegen (Robert A. Heiler).


I have no strong opinion either way but I can understand the 
assumption by st0012 to some extent. For example, I personally
always seem to think more about .include? than .cover?, largely
because I simply use .include? a lot more. I once even added
some .partial_include? method to Enumerable (or somewhere else,
I don't remember ... was years ago).

The other thing is DateTime, Date, and Time. Personally I'd love
if we could have just one-ring-to-rule-them-all one day, perhaps
in ruby 4.0 or so - I think that is a partial complaint by Stan,
in the sense of the behaviour he showed (but I am assuming this
here). But again, I have no real strong opinion either way.

Would be interesting to ask Stan Lo whether he knew about 
.cover? or not. :)

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

* Author: st0012 (Stan Lo)
* Status: Open
* 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>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.