File tree Expand file tree Collapse file tree 1 file changed +3
-16
lines changed Expand file tree Collapse file tree 1 file changed +3
-16
lines changed Original file line number Diff line number Diff line change @@ -1808,22 +1808,9 @@ date.all_quarter
18081808date.all_year
18091809----
18101810
1811- === Comparison
1811+ === Time Comparison
18121812
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.
18271814
18281815[source,ruby]
18291816----
@@ -1836,7 +1823,7 @@ grand_opening_at.past?
18361823public_release_at.future?
18371824----
18381825
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 .
18401827
18411828== Duration
18421829
You can’t perform that action at this time.
0 commit comments