File tree 1 file changed +3
-16
lines changed
1 file changed +3
-16
lines changed Original file line number Diff line number Diff line change @@ -1808,22 +1808,9 @@ date.all_quarter
1808
1808
date.all_year
1809
1809
----
1810
1810
1811
- === Comparison
1811
+ === Time Comparison
1812
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.
1813
+ Use `past?` and `future?` methods instead of comparing time to the current time.
1827
1814
1828
1815
[source,ruby]
1829
1816
----
@@ -1836,7 +1823,7 @@ grand_opening_at.past?
1836
1823
public_release_at.future?
1837
1824
----
1838
1825
1839
- NOTE: Rails 6.0 or later is required to use `before?` and `after?`.
1826
+ NOTE: Rails 6.0 and later also provide `before?` and `after?` methods to compare two arbitrary time objects .
1840
1827
1841
1828
== Duration
1842
1829
You can’t perform that action at this time.
0 commit comments