[ruby-core:95273] [Ruby master Feature#16244] Add a Time#before? and Time#after? method

From: sawadatsuyoshi@...
Date: 2019-10-07 23:34:55 UTC
List: ruby-core #95273
Issue #16244 has been updated by sawa (Tsuyoshi Sawada).


Jeremy Evans is right about this.

But I agree that your second example

```
birthday > thirteen_years_ago
```

is a bit hard to comprehend. However,

```
birthday.after? thirteen_years_ago
```

is as hard to comprehend. You should not be writing like that. You should either do somthing like

```
birthday + thirteen_years > now
```

or

```
now - birthday < thirteen_years
```


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

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

In This Thread

Prev Next