Skip to content

Add new rubocop rule Rails/AvoidTimeComparison to flag time comparison

Gosia Ksionek requested to merge mk-rubocop-time-now into master

What does this MR do and why?

Sometimes we need to do the time comparison. If we compare a datetime to Time.current or Time.zone.now, we can use method like .past? or .future? for readability instead.

In the past I changed places in the code, this MR adds a rubocop rule to prevent adding new places with comparison instead this handy methods.

related MRs:

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Add place in the code with time comparison, such as variable > Time.zone.now
  2. Run rubocop against this file.

Merge request reports