Project

General

Profile

Actions

Bug #16440

closed

Date range inclusion behaviors are inconsistent

Added by st0012 (Stan Lo) almost 5 years ago. Updated almost 5 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
[ruby-core:96377]

Description

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0