File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1808,6 +1808,36 @@ date.all_quarter
1808
1808
date.all_year
1809
1809
----
1810
1810
1811
+ === Comparison
1812
+
1813
+ Avoid comparing time with `>` and `<` to avoid confusion.
1814
+
1815
+ [source,ruby]
1816
+ ----
1817
+ # bad
1818
+ created_at < 5.minutes.ago
1819
+ shutdown_at > 1.minute.from_now
1820
+
1821
+ # good
1822
+ created_at.before?(5.minutes.ago)
1823
+ shutdown_at.after?(1.minute.from_now)
1824
+ ----
1825
+
1826
+ Use `past?` and `future?` when comparing with the current time.
1827
+
1828
+ [source,ruby]
1829
+ ----
1830
+ # bad
1831
+ grand_opening_at < Time.current
1832
+ public_release_at > Time.current
1833
+
1834
+ # good
1835
+ grand_opening_at.past?
1836
+ public_release_at.future?
1837
+ ----
1838
+
1839
+ NOTE: Rails 6.0 or later is required to use `before?` and `after?`.
1840
+
1811
1841
== Duration
1812
1842
1813
1843
=== Duration Application
You can’t perform that action at this time.
0 commit comments