private function timeAgo($timestamp) {
    $now = new \DateTime('now');
    $date = new \DateTime();
    $date->setTimestamp($timestamp);
    $datediff = date_diff($now, $date);
    $message = '';
    $components = [
      ['y', 'year', 'years'], ['m', 'month', 'months'],
      ['d', 'day', 'days'], ['h', 'hour', 'hours'],
      ['i', 'minute', 'minutes'], ['s', 'second', 'seconds'],
    ];
    foreach ($components as $component) {
      if ($datediff->{$component[0]} > 0) {
        $message = $datediff->{$component[0]} . ' '
          . ($datediff->{$component[0]} > 1 ? t($component[2]) : $component[1]);
        break;
      }
    }
    return !empty($message) ? $message . ' ' . t('ago') : '';
  }
private function timeAgo($timestamp) {
    $now = new \DateTime('now');
    $date = new \DateTime();
    $date->setTimestamp($timestamp);
    $datediff = date_diff($now, $date);
    $message = '';
    $components = [
      ['y', 'year', 'years'], ['m', 'month', 'months'],
      ['d', 'day', 'days'], ['h', 'hour', 'hours'],
      ['i', 'minute', 'minutes'], ['s', 'second', 'seconds'],
    ];
    foreach ($components as $component) {
      if ($datediff->{$component[0]} > 0) {
        $message = $datediff->{$component[0]} . ' '
          . ($datediff->{$component[0]} > 1 ? t($component[2]) : $component[1]);
        break;
      }
    }
    return !empty($message) ? $message . ' ' . t('ago') : '';
  }
private function timeAgo ( $ timestamp ) { $ now = new \ DateTime ( 'now' ) ; $ date = new \ DateTime ( ) ; $ date -> setTimestamp ( $ timestamp ) ; $ datediff = date_diff ( $ now , $ date ) ; $ message = '' ; $ components = [ [ 'y' , 'year' , 'years' ] , [ 'm' , 'month' , 'months' ] , [ 'd' , 'day' , 'days' ] , [ 'h' , 'hour' , 'hours' ] , [ 'i' , 'minute' , 'minutes' ] , [ 's' , 'second' , 'seconds' ] , ] ; foreach ( $ components as $ component ) { if ( $ datediff -> { $ component [ 0 ] } > 0 ) { $ message = $ datediff -> { $ component [ 0 ] } . ' ' . ( $ datediff -> { $ component [ 0 ] } > 1 ? t ( $ component [ 2 ] ) : $ component [ 1 ] ) ; break ; } } return ! empty ( $ message ) ? $ message . ' ' . t ( 'ago' ) : '' ; }
Returns a string date comparison in the format "1 day ago" etc.

@param string $timestamp

@return string
Returns a string date comparison in the format 1 day ago etc .