private function getClosestDateBefore(\DateTime $date)
{
$tmpDate = clone $date;
$dayOfWeek = (int) $tmpDate->format('N');
$time = Time::fromDate($tmpDate);
if (!$this->holidays->isHoliday($tmpDate) && null !== ($day = $this->getDay($dayOfWeek))) {
if (null !== ($closestTime = $day->getClosestOpeningTimeBefore($time, $tmpDate))) {
$tmpDate->setTime($closestTime->getHours(), $closestTime->getMinutes(), $closestTime->getSeconds());
return $tmpDate;
}
}
$tmpDate = $this->getDateBefore($tmpDate);
while ($this->holidays->isHoliday($tmpDate)) {
$tmpDate = $this->getDateBefore($tmpDate);
}
$closestDay = $this->getClosestDayBefore((int) $tmpDate->format('N'));
$closingTime = $closestDay->getClosingTime($tmpDate);
$tmpDate->setTime($closingTime->getHours(), $closingTime->getMinutes(), $closingTime->getSeconds());
return $tmpDate;
}