From 1476c8a419a0cdcd5cd9de1412c57fd3f958abe9 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sat, 27 Jul 2024 00:41:32 +0300 Subject: [PATCH] Add the time comparison guideline --- README.adoc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.adoc b/README.adoc index 47652a5..ba711a2 100644 --- a/README.adoc +++ b/README.adoc @@ -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