export default function()

in public/src/js/utils/human-time.js [3:33]


export default function(date, now) {
    var periods = [
            { secs: 30758400, unit: 'year'},
            { secs: 2384640, unit: 'month'},
            { secs: 86400, unit: 'day'},
            { secs: 3600, unit: 'hour'},
            { secs: 60, unit: 'min'}
        ],
        period,
        elapsed,
        abs,
        units,
        str;

    if (!date) { return; }

    elapsed = ((now || new Date()) - new Date(date)) / 1000;

    abs = Math.abs(elapsed);

    period = _.find(periods, function(period) { return abs >= period.secs; });

    units = period ? Math.round(abs / period.secs) : null;

    if (period) {
        str = units + ' ' + period.unit + (units !== 1 ? 's' : '');
        return elapsed < abs ? 'in ' + str : str + ' ago';
    } else {
        return 'just now';
    }
}