---
title: mas o menos
teaser:
tags: web,ruby
author: Jared Carroll
published_on: 2008-04-17
---

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](http://snippets.dzone.com/posts/show/5022) have already a real solid
impl of these 2 queries.  LEFT\_SIDE\_LATER!

..in other news...

![''](http://74.54.212.169/1TEAMALps7xdoi2tdTD4PDpI_400.jpg)
