src/util/Date.php
public static function fuzzySpan($timestamp, $local_timestamp = null) {
        $local_timestamp = ($local_timestamp === null) ? time() : (int)$local_timestamp;

        // Determine the difference in seconds
        $offset = abs($local_timestamp - $timestamp);

        if ($offset <= static::MINUTE) {
            $span = 'moments';
        } elseif ($offset < (static::MINUTE * 20)) {
            $span = 'a few minutes';
        } elseif ($offset < static::HOUR) {
            $span = 'less than an hour';
        } elseif ($offset < (static::HOUR * 4)) {
            $span = 'a couple of hours';
        } elseif ($offset < static::DAY) {
            $span = 'less than a day';
        } elseif ($offset < (static::DAY * 2)) {
            $span = 'about a day';
        } elseif ($offset < (static::DAY * 4)) {
            $span = 'a couple of days';
        } elseif ($offset < static::WEEK) {
            $span = 'less than a week';
        } elseif ($offset < (static::WEEK * 2)) {
            $span = 'about a week';
        } elseif ($offset < static::MONTH) {
            $span = 'less than a month';
        } elseif ($offset < (static::MONTH * 2)) {
            $span = 'about a month';
        } elseif ($offset < (static::MONTH * 4)) {
            $span = 'a couple of months';
        } elseif ($offset < static::YEAR) {
            $span = 'less than a year';
        } elseif ($offset < (static::YEAR * 2)) {
            $span = 'about a year';
        } elseif ($offset < (static::YEAR * 4)) {
            $span = 'a couple of years';
        } elseif ($offset < (static::YEAR * 8)) {
            $span = 'a few years';
        } elseif ($offset < (static::YEAR * 12)) {
            $span = 'about a decade';
        } elseif ($offset < (static::YEAR * 24)) {
            $span = 'a couple of decades';
        } elseif ($offset < (static::YEAR * 64)) {
            $span = 'several decades';
        } else {
            $span = 'a long time';
        }

        if ($timestamp <= $local_timestamp) {
            // This is in the past
            return $span . ' ago';
        } else {
            // This in the future
            return 'in ' . $span;
        }
    }
public static function fuzzySpan($timestamp, $local_timestamp = null) {
        $local_timestamp = ($local_timestamp === null) ? time() : (int)$local_timestamp;

        // Determine the difference in seconds
        $offset = abs($local_timestamp - $timestamp);

        if ($offset <= static::MINUTE) {
            $span = 'moments';
        } elseif ($offset < (static::MINUTE * 20)) {
            $span = 'a few minutes';
        } elseif ($offset < static::HOUR) {
            $span = 'less than an hour';
        } elseif ($offset < (static::HOUR * 4)) {
            $span = 'a couple of hours';
        } elseif ($offset < static::DAY) {
            $span = 'less than a day';
        } elseif ($offset < (static::DAY * 2)) {
            $span = 'about a day';
        } elseif ($offset < (static::DAY * 4)) {
            $span = 'a couple of days';
        } elseif ($offset < static::WEEK) {
            $span = 'less than a week';
        } elseif ($offset < (static::WEEK * 2)) {
            $span = 'about a week';
        } elseif ($offset < static::MONTH) {
            $span = 'less than a month';
        } elseif ($offset < (static::MONTH * 2)) {
            $span = 'about a month';
        } elseif ($offset < (static::MONTH * 4)) {
            $span = 'a couple of months';
        } elseif ($offset < static::YEAR) {
            $span = 'less than a year';
        } elseif ($offset < (static::YEAR * 2)) {
            $span = 'about a year';
        } elseif ($offset < (static::YEAR * 4)) {
            $span = 'a couple of years';
        } elseif ($offset < (static::YEAR * 8)) {
            $span = 'a few years';
        } elseif ($offset < (static::YEAR * 12)) {
            $span = 'about a decade';
        } elseif ($offset < (static::YEAR * 24)) {
            $span = 'a couple of decades';
        } elseif ($offset < (static::YEAR * 64)) {
            $span = 'several decades';
        } else {
            $span = 'a long time';
        }

        if ($timestamp <= $local_timestamp) {
            // This is in the past
            return $span . ' ago';
        } else {
            // This in the future
            return 'in ' . $span;
        }
    }
Returns the difference between a time and now in a "fuzzy" way.
Displaying a fuzzy time instead of a date is usually faster to read and understand.

$span = Date::fuzzy_span(time() - 10); // "moments ago"
$span = Date::fuzzy_span(time() + 20); // "in moments"

A second parameter is available to manually set the "local" timestamp,
however this parameter shouldn't be needed in normal usage and is only
included for unit tests

@param   integer $timestamp "remote" timestamp
@param   integer $local_timestamp "local" timestamp, defaults to time()
@return  string