Rails adds before? after? methods on date time classes
Rails Date, DateTime, Time, TimeWithZone class objects
could be compared using less than,
greater than signs.
Rails
added methods
before?
and
after?
to compare objects
of these datetime classes.
ActiveSupport core extension
calculation classes
included a alias_method
to <
and >
comparison functions
which were already present.
Before this change
If we want to compare times, we had to use <
and >
operator as given below.
After this change
If we want to compare times, we can use before?
and after
operator as given below.
Usage of before?
for time comparison
Usage of after?
for time comparison
These methods of time comparison are available on Date, Time, DateTime and TimeWithZone classes.
Subscribe to Ruby in Rails
Get the latest posts delivered right to your inbox