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 A03A01F463 for ; Fri, 20 Dec 2019 17:28:38 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B2E64120A79; Sat, 21 Dec 2019 02:28:23 +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 DBF23120A75 for ; Sat, 21 Dec 2019 02:28:20 +0900 (JST) Received: by filterdrecv-p3las1-5bf99c48d-j57ff with SMTP id filterdrecv-p3las1-5bf99c48d-j57ff-19-5DFD04BA-24 2019-12-20 17:28:26.293016931 +0000 UTC m=+319361.932371153 Received: from herokuapp.com (unknown [3.83.106.33]) by ismtpd0107p1mdw1.sendgrid.net (SG) with ESMTP id 0qipF8tqRE2rpzVngaLh9A for ; Fri, 20 Dec 2019 17:28:26.148 +0000 (UTC) Date: Fri, 20 Dec 2019 17:28:26 +0000 (UTC) From: wishdev@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 72038 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16440 X-Redmine-Issue-Author: st0012 X-Redmine-Sender: wishdev 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?Z4Ej7Bg37lK69JtZPFJ+UW67gqYKj9Iu8E0xhUBC8OWIlJPnHzvSAOCPFG6FY7?= =?us-ascii?Q?WEFCebKpb38xnWY=2FWkBi0pnv1qYyMe4GioGX6pT?= =?us-ascii?Q?EoW4JBEZwSIYhKKnDK9mZLerLdN3xZ61QfrRoVj?= =?us-ascii?Q?UraGW+LrzqhgIa1lGFLoA+YG0fovPwSU5Xeby7I?= =?us-ascii?Q?off+l6N8=2FXvhRHwvS33ZBC2zZdL9em1gjGk7Z8w?= =?us-ascii?Q?dVtgt1p98p0IRRUTI=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96378 Subject: [ruby-core:96378] [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 wishdev (John Higgins). Nothing strange with your example - but that doesn't mean it totally works right. First your example is a DATE range - so adding this line `(may1..may31).each { |x| puts x }` That shows that your set is each day within the range at Midnight - therefore any other time is not included (and in fact on my system - the to_time option returns false instead of true). BUT, on the other hand - one might imagine that something like `may1 = DateTime.parse("2019-05-01") may31 = DateTime.parse("2019-05-31") noon_of_may3 = DateTime.parse("2019-05-03 12:00") (may1..may31).include? noon_of_may3` Should get a true for the include It appears though, that DateTime ranges only use the exact Time each day of the range `(may1..may31).each { |x| puts x }` Shows this with the DateTime range. So I don't believe there is an issue with the code as you have it - but there might be a conversation as to why a DateTime range does not appear to work for your example. John ---------------------------------------- Bug #16440: Date range inclusion behaviors are inconsistent https://bugs.ruby-lang.org/issues/16440#change-83299 * 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/