Habari\DateTime::friendly PHP Метод

friendly() публичный Метод

Returns a friendlier string version of the time, ie: 3 days, 1 hour, and 5 minutes ago
public friendly ( integer $precision = 7, boolean $include_suffix = true, $comparison_date = 'now' ) : string
$precision integer Only display x intervals. Note that this does not round, it only limits the display length.
$include_suffix boolean Include the 'ago' or 'from now' suffix?
Результат string Time passed in the specified units.
    public function friendly($precision = 7, $include_suffix = true, $comparison_date = 'now')
    {
        $difference = self::difference($comparison_date, $this);
        $result = array();
        if ($difference['y']) {
            $result[] = sprintf('%d %s', $difference['y'], _n('year', 'years', $difference['y']));
        }
        if ($difference['m']) {
            $result[] = sprintf('%d %s', $difference['m'], _n('month', 'months', $difference['m']));
        }
        if ($difference['w']) {
            $result[] = sprintf('%d %s', $difference['w'], _n('week', 'weeks', $difference['w']));
        }
        if ($difference['d']) {
            $result[] = sprintf('%d %s', $difference['d'], _n('day', 'days', $difference['d']));
        }
        if ($difference['h']) {
            $result[] = sprintf('%d %s', $difference['h'], _n('hour', 'hours', $difference['h']));
        }
        if ($difference['i']) {
            $result[] = sprintf('%d %s', $difference['i'], _n('minute', 'minutes', $difference['i']));
        }
        if ($difference['s']) {
            $result[] = sprintf('%d %s', $difference['s'], _n('second', 'seconds', $difference['s']));
        }
        // limit the precision
        $result = array_slice($result, 0, $precision);
        $result = Format::and_list($result);
        if ($include_suffix) {
            if ($difference['invert'] == true) {
                $result = _t('%s from now', array($result));
            } else {
                $result = _t('%s ago', array($result));
            }
        }
        return $result;
    }