Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1476c8a

Browse files
committed
Add the time comparison guideline
1 parent 524a1ac commit 1476c8a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎README.adoc‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,23 @@ date.all_quarter
18081808
date.all_year
18091809
----
18101810

1811+
=== Time Comparison
1812+
1813+
Use `past?` and `future?` methods instead of comparing time to the current time.
1814+
1815+
[source,ruby]
1816+
----
1817+
# bad
1818+
grand_opening_at < Time.current
1819+
public_release_at > Time.current
1820+
1821+
# good
1822+
grand_opening_at.past?
1823+
public_release_at.future?
1824+
----
1825+
1826+
NOTE: Rails 6.0 and later also provide `before?` and `after?` methods to compare two arbitrary time objects.
1827+
18111828
== Duration
18121829

18131830
=== Duration Application

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /