/** * Get the shift that begins before a date and a time and ends after * the same. * * @param \DateTime $dayTime * @return null|Shift */ public function getResponsibleShiftForDayAndTime(\DateTime $dayTime) { $timeService = $this->container->get('tixi_api.datetimeservice'); $shiftRepo = $this->container->get('shift_repository'); $shiftsForDay = $shiftRepo->findShiftsForDay($dayTime); $pickTime = $timeService->convertToLocalDateTime($dayTime); foreach ($shiftsForDay as $shift) { $startTime = $timeService->convertToLocalDateTime($shift->getStartDate()); $endTime = $timeService->convertToLocalDateTime($shift->getEndDate()); if (DateTimeService::matchTimeBetweenTwoDateTimes($pickTime, $startTime, $endTime)) { return $shift; } } return null; }
/** * @param \DateTime $dateTime * @return bool */ public function isResponsibleForTime(\DateTime $dateTime) { return DateTimeService::matchTimeBetweenTwoDateTimes($dateTime, $this->start, $this->end); }