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.8 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 8921E1F4BD for ; Tue, 8 Oct 2019 23:27:12 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3B9DA120929; Wed, 9 Oct 2019 08:27:01 +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 457BC1208FD for ; Wed, 9 Oct 2019 08:26:59 +0900 (JST) Received: by filter0173p3mdw1.sendgrid.net with SMTP id filter0173p3mdw1-22977-5D9D1B42-78 2019-10-08 23:26:59.001458968 +0000 UTC m=+110059.606865837 Received: from herokuapp.com (unknown [54.157.57.165]) by ismtpd0096p1iad2.sendgrid.net (SG) with ESMTP id wce2z9s8SxWuN6KUnhM0AQ for ; Tue, 08 Oct 2019 23:26:58.846 +0000 (UTC) Date: Tue, 08 Oct 2019 23:26:58 +0000 (UTC) From: stevendaniels88@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70871 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16244 X-Redmine-Issue-Author: stevendaniels X-Redmine-Sender: stevendaniels 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?wmILHqzqLVzb3UFOeitWvWAgTOPWggHIH6J4WQp2V6UN90OSbK0jadX=2FlBu9yQ?= =?us-ascii?Q?Hxh8cSr+sxPOlYyYbI2VE1rznEFLu=2F4YQ+C0XRG?= =?us-ascii?Q?y=2F4X4knpHElIK5oa=2Fxz7t3trp26e5x482JhM9C6?= =?us-ascii?Q?bChU3LmAlSQecxIDs1ru44M8LJn5tUlfXR6yMy=2F?= =?us-ascii?Q?07VGnL5LtE0RZsf+uxZysqhmBeNkS+EuGqg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95284 Subject: [ruby-core:95284] [Ruby master Feature#16244] Add a Time#before? and Time#after? method 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 #16244 has been updated by stevendaniels (Steven Daniels). sawa (Tsuyoshi Sawada) wrote: >You should not be writing like that. You should either do somthing like > > ``` > birthday + thirteen_years > now > ``` > > or > > ``` > now - birthday < thirteen_years > ``` In your example, your coercing the dates to Floats and then comparing integers. Part of the reason I think `before?`/`after?` would be a good addition is because they remove the need to coerce a `Time` in order to do a comparison. I think your solution illustrates part of the problem I agree that my example in the beginning isn't perfect. A better example might be this: ```ruby steven.birthday.before? john.birthday ``` instead of ```ruby steven.birthday < john.birthday ``` I have a more basic question: are there specific criteria for accepting alias methods for core objects? Is Ruby's preference to avoid adding alias methods? ---------------------------------------- Feature #16244: Add a Time#before? and Time#after? method https://bugs.ruby-lang.org/issues/16244#change-81964 * Author: stevendaniels (Steven Daniels) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Comparing times using `>` and`<` can be pretty confusing. I'd like to propose `Time#before?` and `Time#after?` methods for aliasing `Time#<` and `Time#>` These method aliases would make the code more readable. :) Current syntax: ``` ruby if current_time < expiration_at # do stuff end if birthday > thirteen_years_ago # you need a parent's permission to sign up end ``` What I'd like to see added: ``` ruby if current_time.before? expiration_at # do stuff end if birthday.after? thirteen_years_ago # you need a parent's permission to sign up end ``` Thanks for your consideration! -- https://bugs.ruby-lang.org/