setTime(0, 0)->diff($endDate->setTime(0, 0))->format('%a')) + 1; do { $workingDaysCount = (int) ($startDate->setTime(0, 0)->diff($endDate->setTime(0, 0))->format('%a')) + 1; $workingDaysCountInInterval = $this->workingDayDeterminer->getWorkingDaysCount($startDate, $workingDaysCount); if ($workingDaysCountInInterval >= $requiredWorkingDaysCount) { // there is no weekends or holidays in the given interval break; } else { $endDate = $endDate->add(new \DateInterval(sprintf('P%dD', $requiredWorkingDaysCount - $workingDaysCountInInterval))); if ($loopId > static::MAX_ITERATIONS) { throw new \InvalidArgumentException('No working days found in the given interval'); } } $loopId++; } while ($workingDaysCount != $workingDaysCountInInterval); return $endDate; } }