Issue #16244 has been updated by stevendaniels (Steven Daniels).


jeremyevans0 (Jeremy Evans) wrote:


> I would guess the `>` and `<` symbols are probably more understandable to people whose native language is not English, at least.

It's hard to speak for all non-native English speakers one way or the other, but in the languages non-English languages I speak, using **greater than** and **less than** to compare times isn't a natural way to frame the comparison; by comparison, before and after is a natural way to compare times in most languages.

Over the years I've seen this confusion manifested by developers of all levels of experience leading to real life bugs. Adding aliases that help to alleviate that confusion would be a nice thing to provide to all Ruby developers (which is why I'm making this feature request).

Subjectively speaking, comparisons like`if blog.published_at.before? Time.now` feel more natural than `if blog.published_at < Time.now`. 

(Big fan of your work, BTW!)


----------------------------------------
Feature #16244: Add a Time#before? and Time#after? method
https://bugs.ruby-lang.org/issues/16244#change-81940

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>