protected function divideBusinessHours($entity) { //var_dump($entity->getPlace());die(); $today = new \DateTime(); if ($entity->getStartsAt()->format('H:i:s') > $entity->getEndsAt()->format('H:i:s')) { //var_dump($entity->getPlace(). 'dddd');die(); $endsAt = $entity->getEndsAt(); $entity->setEndsAt($today::createFromFormat('H:i:s', '23:59:59')); $bh = new BusinessHours(); DayFlaggableHelper::fillFields($bh, false); $pa = PropertyAccess::createPropertyAccessor(); foreach (DayFlaggableHelper::getWeekdays() as $key => $label) { if ($pa->getValue($entity, 'day' . ucwords($key)) == true) { $nextDay = DayFlaggableHelper::nextDay($key); $pa->setValue($bh, 'day' . ucwords($nextDay), true); } } //var_dump($entity->getPlace()); $bh->setPlace($entity->getPlace()); $bh->setStartsAt($today::createFromFormat('H:i:s', '00:00:00')); $bh->setEndsAt($endsAt); $this->entities[] = $bh; } }
protected function getClosestOpenHours($place) { $now = new \DateTime(); $day = $now->format('l'); $dayOpenMin = new \DateTime('+10 years'); //Dummy foreach ($place->getBusinessHours() as $bh) { $endsAt = $bh->getEndsAt(); $startsAt = $bh->getStartsAt(); for ($i = 1; $i <= 7; $i++) { $method = 'getDay' . ucfirst($day); $dayOpen = new \Datetime($day); $dayOpen->setTime($startsAt->format('H'), $startsAt->format('i'), $startsAt->format('s')); if ($bh->{$method}() && $dayOpen > $now) { //Looking for soonest open hours if ($dayOpen < $dayOpenMin) { $dayOpenMin = $dayOpen; } } $day = DayFlaggableHelper::nextDay($day); } } return $dayOpenMin; }