rubocop / rails-style-guide

A community-driven Ruby on Rails style guide
http://rails.rubystyle.guide
6.47k stars 1.06k forks source link

ActiveSupport::Duration comparison #269

Closed pirj closed 3 years ago

pirj commented 4 years ago

Might be just me, but I found the following confusing:

TRIAL_PERIOD = 2.weeks
# ...
if created_at > TRIAL_PERIOD.ago
# or
if created_at > 2.weeks.ago

if sounded like "if created more than two weeks ago", but actually checks if it was created less than two weeks ago.

Is there a better way? I can think of:

if TRIAL_PERIOD.since(created_at).past?
#
if created_at.between?(TRIAL_PERIOD.ago, Time.current)

Is it any better?

pirj commented 3 years ago

This didn't get much positive response.