Everyone seems to trip up when it comes to #< and #> and dates and times.
def recent if published_on > 1.week.ago # blah end end def old if published_on < 1.week.ago # blah end end
Nobody thinks of dates and times as numbers, so its hard to do comparisons on them quickly like you would with numbers. So lets add 2 methods to our dates and times.
def after?(other) self > other end def before?(other) self < other end def recent if published_on.after?(1.week.ago) # blah end end def old if published_on.before?(1.week.ago) # blah end end
Luckily our good friends over at dzone have already a real solid impl of these 2 queries. LEFT_SIDE_LATER!
..in other news…