Rails 6 adds reselect on ActiveRecord Relation
December 05, 2019
Before Rails 6.0, the date/time are compared by using the equality operators like less than (<) or greater than (>), etc. Sometimes, date/time comparison using these operators takes some time to understand as these conventions are not human-readable at least for dates.
Date.yesterday < Date.today # trueTime.current < (Time.current - 1.hour) # false(DateTime.current - 1.day) < DateTime.current # trueDateTime.current < (DateTime.current - 1.day) # false
Date.yesterday.before? Date.today # trueTime.current.after? (Time.current - 1.hour) # false(DateTime.current - 1.day).before? DateTime.current # trueDateTime.current.after? (DateTime.current - 1.day) # false
The methods before? and after? are more human-readable and easy to understand than using the equality operators ( \’<\’ and \’>\’) to compare the Date, Time, DateTime, and TimeWithZone objects