You are here

public function CarbonInterval::forHumans in Persian Date for Drupal 8 8.4

Get the current interval in a human readable format in the current locale.

Return value

string

1 call to CarbonInterval::forHumans()
CarbonInterval::__toString in src/Library/Carbon/CarbonInterval.php
Format the instance as a string using the forHumans() function.

File

src/Library/Carbon/CarbonInterval.php, line 470

Class

CarbonInterval
A simple API extension for DateInterval. The implementation provides helpers to handle weeks but only days are saved. Weeks are calculated based on the total days of the current instance.

Namespace

Drupal\persian_date\Library\Carbon

Code

public function forHumans() {
  $periods = array(
    'year' => $this->years,
    'month' => $this->months,
    'week' => $this->weeks,
    'day' => $this->daysExcludeWeeks,
    'hour' => $this->hours,
    'minute' => $this->minutes,
    'second' => $this->seconds,
  );
  $parts = array();
  foreach ($periods as $unit => $count) {
    if ($count > 0) {
      array_push($parts, static::translator()
        ->transChoice($unit, $count, array(
        ':count' => $count,
      )));
    }
  }
  return implode(' ', $parts);
}