ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: anastasia.k.stowers@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:96221] [Ruby master Feature#16244] Add a Time#before? and Time#after? method
Date: Fri, 13 Dec 2019 18:30:44 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-83113.20191213183043.8db48caf1a7c1e9e@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16244.20191007164739@ruby-lang.org

Issue #16244 has been updated by anastasiastowers (Anastasia Stowers).


Using the > and < symbols makes sense to compare Time only with the knowledge of the underlying unix time system being used.

Although this is the way that we choose to store values of it in our systems, Time is special because it has direction in the way that we perceive it. The words “before” and “after” the only words we use to compare it when considering infinitesimally close event values.

I think the promotion of “natural language” is the direction that Ruby has been going.

Some examples of preferring “natural language”:
https://bugs.ruby-lang.org/issues/12746
https://bugs.ruby-lang.org/issues/13784
https://bugs.ruby-lang.org/issues/14043
https://bugs.ruby-lang.org/issues/14697

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

* 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/

  parent reply	other threads:[~2019-12-13 18:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16244.20191007164739@ruby-lang.org>
2019-10-07 16:47 ` [ruby-core:95260] [Ruby master Feature#16244] Add a Time#before? and Time#after? method stevendaniels88
2019-10-07 17:07 ` [ruby-core:95261] " merch-redmine
2019-10-07 19:43 ` [ruby-core:95263] " stevendaniels88
2019-10-07 23:34 ` [ruby-core:95273] " sawadatsuyoshi
2019-10-08 23:26 ` [ruby-core:95284] " stevendaniels88
2019-10-09  6:52 ` [ruby-core:95287] " keithrbennett
2019-12-13 18:30 ` anastasia.k.stowers [this message]
2019-12-15  0:59 ` [ruby-core:96241] " nobu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-83113.20191213183043.8db48caf1a7c1e9e@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).