You are here

public function Carbon::diffFiltered in Persian Date for Drupal 8 8.4

Get the difference by the given interval using a filter closure

Parameters

CarbonInterval $ci An interval to traverse by:

Closure $callback:

Carbon|null $dt:

bool $abs Get the absolute of the difference:

Return value

int

2 calls to Carbon::diffFiltered()
Carbon::diffInDaysFiltered in src/Library/Carbon/Carbon.php
Get the difference in days using a filter closure
Carbon::diffInHoursFiltered in src/Library/Carbon/Carbon.php
Get the difference in hours using a filter closure

File

src/Library/Carbon/Carbon.php, line 2665

Class

Carbon
A simple API extension for DateTime

Namespace

Drupal\persian_date\Library\Carbon

Code

public function diffFiltered(CarbonInterval $ci, Closure $callback, Carbon $dt = null, $abs = true) {
  $start = $this;
  $end = $dt ?: static::now($this
    ->getTimezone());
  $inverse = false;
  if ($end < $start) {
    $start = $end;
    $end = $this;
    $inverse = true;
  }
  $period = new DatePeriod($start, $ci, $end);
  $vals = array_filter(iterator_to_array($period), function (DateTime $date) use ($callback) {
    return call_user_func($callback, Carbon::instance($date));
  });
  $diff = count($vals);
  return $inverse && !$abs ? -$diff : $diff;
}