Issue #16440 has been updated by zverok (Victor Shepelev).


> Does a Date range represent a series of individual days between May 1st and May 31th, like `[2019-05-01 00:00:00, 2019-05-02 00:00:00..... 2019-05-31 00:00:00]` ? Or it represents a continuous time range that starts from May 1st's 00:00 to May 31th's 00:00?

It (Range in general, nothing special about date Range) represents both, depending on the context. 

* In Enumerable context (for example, if you'll try to do `(may1..may31).to_a`, or `.select` or `.any?`; or `include?`) it represents a series. 
* In the diapason context (`cover?`, `===`) it represents the entire space between beginning and end. That's true for every kind of range, and even if not entirely obvious always, is easy to explain and remember without edge cases (which the linked Rails PR tries to introduce: "if you don't know `include?` is discontinous, we got you covered, bro!").

> I think it should return true for `(may1..may31).include? may3.to_time`. 

The reason it doesn't is not related to the Range itself, but to the fact that `Date` is library class and `Time` is core class, and they are not compatible. This is also `false`:

```ruby
may3 == may3.to_time
# => false 
```

I hate this fact myself and tried to argue about it (that we need core `Date` class), but Powers That Be think about `date` as "scientific" dates library rarely needed, while Rails team and Rails users used to think about it as a generic "just date" class.

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

* 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:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>