From: stevendaniels88@... Date: 2019-10-08T23:26:58+00:00 Subject: [ruby-core:95284] [Ruby master Feature#16244] Add a Time#before? and Time#after? method 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/ Unsubscribe: