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;
    }
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;
    }
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 ; }
Gets the closest business date before the given date.

@param \DateTime $date

@return \DateTime
Gets the closest business date before the given date .