var dateAgo = function(unixTime) {

    var pluralize = function(amt) {
        return (amt >= 1 && amt < 2) ? "" : "s";
    }

    if (typeof unixTime === "Date") {
        unixTime = unixTime.getTime();
    }
    else if (typeof unixTime === "string") {
        unixTime = Date.parse(unixTime);
    }

    var ms = new Date().getTime() - unixTime;

    if ((secs = ms / 1000) < 1) {
        amount = ms + " ms";
    }
    else if ((mins = secs / 60) < 1) {
        amount = secs.toFixed(0) + " sec" + pluralize(secs);
    }
    else if ((hours = mins / 60) < 1) {
        amount = Math.floor(mins) + " min" + pluralize(mins);
    }
    else if ((days = hours / 24) < 1) {
        amount = Math.floor(hours) + " hour" + pluralize(hours);
    }
    else if ((weeks = days / 7) < 1) {
        amount = Math.floor(days) + " day" + pluralize(days);
    }
    else if ((months = days / 30) < 1) {
        amount = Math.floor(weeks) + " week" + pluralize(weeks);
    }
    else if ((years = days / 365) < 1) {
        amount = Math.floor(months) + " month" + pluralize(months);
    }
    else {
        amount = Math.floor(years) + " year" + pluralize(years);
    }

    return amount + " ago";
};

