-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DateTime range include?
returns wrong output (or so I think)
#30799
Comments
include?
returns wrong output (or so I think)
On your use case You need to use |
ActiveSupport extends So it fails because of the What is also confusing is that it works with Time but not DateTime. |
@apneadiving : have a look at:
|
@nicolasblanco indeed this is what I describe :) it works fine with Time but not with DateTime. |
About your question on why you have a different behaviour between a range of DateTimes and a range of Times: Ruby has a customized way of dealing with a range of Times. For this reason, you cannot convert a range of Times to an array:
But you can convert a range of DateTimes to an array:
As you see, when converting a range of DateTimes to an array, Ruby has a granularity of 1 day between each DateTime. That's why you don't have the expected behaviour when using |
The whole point of my issue is questionning the inconsistency of what |
Looks like https://bugs.ruby-lang.org/issues/11113 Since it isn't, the default |
The issue with |
In #11474 we prevented TWZ ranges being iterated over which matched Ruby's handling of Time ranges and as a consequence `include?` stopped working with both Time ranges and TWZ ranges. However in ruby/ruby@b061634 support was added for `include?` to use `cover?` for 'linear' objects. Since we have no way of making Ruby consider TWZ instances as 'linear' we have to override `Range#include?`. Fixes #30799.
Steps to reproduce
Expected behavior
ts1.include? ts2.first
should returntrue
Actual behavior
ts1.include? ts2.first
returnsfalse
Side notes
Interestingly enough, if you use
Time
instead ofDateTime
, it works as expected.With Ruby only, it does not work...
System configuration
Rails version: 5.1.3
Ruby version: 2.4.2
The text was updated successfully, but these errors were encountered: