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.6 required=3.0 tests=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 6F08E1F463 for ; Sat, 21 Dec 2019 15:25:44 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 97D1B120A6B; Sun, 22 Dec 2019 00:25:31 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 1BBAE120A69 for ; Sun, 22 Dec 2019 00:25:29 +0900 (JST) Received: by filterdrecv-p3las1-5bf99c48d-527wg with SMTP id filterdrecv-p3las1-5bf99c48d-527wg-18-5DFE396D-E 2019-12-21 15:25:33.301934434 +0000 UTC m=+398384.037434133 Received: from herokuapp.com (unknown [75.101.247.47]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id gDqTOX8kQe2gde7zbAXpag for ; Sat, 21 Dec 2019 15:25:33.156 +0000 (UTC) Date: Sat, 21 Dec 2019 15:25:33 +0000 (UTC) From: zverok.offline@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72050 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=2FmHQTWm54P5gda7yGp4zieGl7iBPUK8buf?= =?us-ascii?Q?QsKEqBfAeBY9npcFOWQvUxIjAdbWpg404n3pspq?= =?us-ascii?Q?I5XLY0BFIht=2FYkPoRzNsS1Lyd9aEFTVKNfW5X4H?= =?us-ascii?Q?B3Xnh8WveNVqvKVInQyLGZJU1xHfSdhW3ZYS+17?= =?us-ascii?Q?9JcRvtVgAWdlqoeRb4jcz85Vh+QHKXDZ4hi36+w?= =?us-ascii?Q?5jQj9Epmc=2FI0Ciy3o=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96390 Subject: [ruby-core:96390] [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). > 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/