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 A83241F463 for ; Sat, 21 Dec 2019 15:06:02 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 4657C120A60; Sun, 22 Dec 2019 00:05:49 +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 9AF36120A43 for ; Sun, 22 Dec 2019 00:05:46 +0900 (JST) Received: by filterdrecv-p3mdw1-56c97568b5-thcqq with SMTP id filterdrecv-p3mdw1-56c97568b5-thcqq-18-5DFE34CD-65 2019-12-21 15:05:49.885814664 +0000 UTC m=+397363.274474374 Received: from herokuapp.com (unknown [75.101.247.47]) by ismtpd0034p1iad2.sendgrid.net (SG) with ESMTP id nqvXYfrPR36GHkEsPi0hsA for ; Sat, 21 Dec 2019 15:05:49.819 +0000 (UTC) Date: Sat, 21 Dec 2019 15:05:49 +0000 (UTC) From: stan001212@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72049 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16440 X-Redmine-Issue-Author: st0012 X-Redmine-Sender: st0012 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?cNMZzs5JtKI7CACre8zKf8+TaokBVqw22oA+ftxPRbGYWay9u7ZQP3gdFv2rmi?= =?us-ascii?Q?Svq3S+mCeuiMcV9964THUAZfB+1RT39wbNVXM3E?= =?us-ascii?Q?B9qkepXXnxWu1PM+RvNUwXAkYmp0opZCiVGGUbO?= =?us-ascii?Q?568IFtkOuuGRxm3UJ6mA9c9OLE4Exm5gFgjrdR4?= =?us-ascii?Q?GaNCbjGAuVc6MRJKsNU1JhYCyCcrJn3MCGQJCnq?= =?us-ascii?Q?KIu31wQtGcnp+wKgY=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96389 Subject: [ruby-core:96389] [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 st0012 (Stan Lo). To: wishdev (John Higgins) > (and in fact on my system - the to_time option returns false instead of true). Sorry that I accidentally tested my code in a Rails console instead of pure irb. The result for that case should be `false` on my machine as well. Let me correct this: ``` 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 # => False (may1..may31).include? may3.to_datetime # => True (may1..may31).include? noon_of_may3 # => False ``` To: zverok (Victor Shepelev) and shevegen (Robert A. Heiler) I think semantically, `cover` might be a better API for such cases. But I'm like `shevegen` don't use `cover` that often. In fact, I completely forgot about it! However, I think my question of this issue is: 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? If it's the first case, I can understand that `include?` doesn't return `true` for `noon_of_may3`. Because it's not at `00:00:00` of that day. But at the same time, I think it should return `true` for `(may1..may31).include? may3.to_time` as well because it's at `00:00:00` of that day. ``` may3.to_time #=> 2019-05-03 00:00:00 +0000 ``` If it's the second case, we should make all 4 cases return `true` because they're all covered by the range. What do you guys think? ---------------------------------------- Bug #16440: Date range inclusion behaviors are inconsistent https://bugs.ruby-lang.org/issues/16440#change-83312 * 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/