Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time comparison guideline #357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,23 @@ date.all_quarter
date.all_year
----

=== Time Comparison

Use `past?` and `future?` methods instead of comparing time to the current time.

[source,ruby]
----
# bad
grand_opening_at < Time.current
public_release_at > Time.current

# good
grand_opening_at.past?
public_release_at.future?
----

NOTE: Rails 6.0 and later also provide `before?` and `after?` methods to compare two arbitrary time objects.

== Duration

=== Duration Application
Expand Down