From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 5F4EC1F463 for ; Fri, 20 Dec 2019 17:55:32 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 0B4D7120A85; Sat, 21 Dec 2019 02:55:18 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4FF6E120A6A for ; Sat, 21 Dec 2019 02:55:16 +0900 (JST) Received: by filterdrecv-p3mdw1-56c97568b5-zwhxv with SMTP id filterdrecv-p3mdw1-56c97568b5-zwhxv-19-5DFD0B05-4F 2019-12-20 17:55:17.454005915 +0000 UTC m=+321130.351698582 Received: from herokuapp.com (unknown [3.83.106.33]) by ismtpd0069p1mdw1.sendgrid.net (SG) with ESMTP id 7UkHZPaoQamm3gY9D3PW3A for ; Fri, 20 Dec 2019 17:55:17.390 +0000 (UTC) Date: Fri, 20 Dec 2019 17:55:17 +0000 (UTC) From: zverok.offline@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72039 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16440 X-Redmine-Issue-Author: st0012 X-Redmine-Sender: zverok X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?3be0g8093pjUjT94eiCA64csFDBI=2FmHQTWm54P5gda4eLVZ8DUlsua5rNB8vSr?= =?us-ascii?Q?Sn=2FOORECxMoqWv3=2FjeYuqLc6e9q=2FJdWKKPopbDW?= =?us-ascii?Q?rYNze62sIYPUgXHX5bP3DriDGxxM3sToTAusxAP?= =?us-ascii?Q?ZDmAZvEkN8Ngc31Qbclu7LByS00WYbb=2FeuKlYdX?= =?us-ascii?Q?sMziAsPVkA9wgMqO3ym8DSu7rp3lEifRZyQZ=2FZn?= =?us-ascii?Q?5=2Fk2j6u4PiAE1Nyqc=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96379 Subject: [ruby-core:96379] [Ruby master Bug#16440] Date range inclusion behaviors are inconsistent X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16440 has been updated by zverok (Victor Shepelev). `Range#include?` works as `#to_a.include?`. E.g. this: ```ruby (may1..may31).include? noon_of_may3 # => false ``` Is equivalent to this: ```ruby dates = (may1..may31).to_a # => each Date between May 1 and 31 dates.include? noon_of_may3 # => false ``` What works as you expect (compare value with range begin and end) is `Range#cover?`: ```ruby (may1..may31).cover? noon_of_may3 # => true ``` (To make things a bit more complicated, there is a special reimplementation for numbers, so `(1...2).include?(1.5)` is `true`.) ---------------------------------------- Bug #16440: Date range inclusion behaviors are inconsistent https://bugs.ruby-lang.org/issues/16440#change-83300 * 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/