/** * @dataProvider dataProviderForTestIsLocationOpen1 */ public function testIsLocationOpen_working_hours_exist($expected, $date) { $location = new Paysera_WalletApi_Entity_Location(); $workingHours1 = new Paysera_WalletApi_Entity_Location_DayWorkingHours(); $workingHours1->setDay(Paysera_WalletApi_Entity_Location_DayWorkingHours::DAY_MONDAY); $workingHours1->setOpeningTime(new Paysera_WalletApi_Entity_Time(9, 0)); $workingHours1->setClosingTime(new Paysera_WalletApi_Entity_Time(18, 0)); $workingHours2 = new Paysera_WalletApi_Entity_Location_DayWorkingHours(); $workingHours2->setDay(Paysera_WalletApi_Entity_Location_DayWorkingHours::DAY_TUESDAY); $workingHours2->setOpeningTime(new Paysera_WalletApi_Entity_Time(9, 0)); $workingHours2->setClosingTime(new Paysera_WalletApi_Entity_Time(18, 0)); $workingHours4 = new Paysera_WalletApi_Entity_Location_DayWorkingHours(); $workingHours4->setDay(Paysera_WalletApi_Entity_Location_DayWorkingHours::DAY_THURSDAY); $workingHours4->setOpeningTime(new Paysera_WalletApi_Entity_Time(9, 0)); $workingHours4->setClosingTime(new Paysera_WalletApi_Entity_Time(18, 0)); $workingHours5 = new Paysera_WalletApi_Entity_Location_DayWorkingHours(); $workingHours5->setDay(Paysera_WalletApi_Entity_Location_DayWorkingHours::DAY_FRIDAY); $workingHours5->setOpeningTime(new Paysera_WalletApi_Entity_Time(22, 0)); $workingHours5->setClosingTime(new Paysera_WalletApi_Entity_Time(3, 0)); $workingHours7 = new Paysera_WalletApi_Entity_Location_DayWorkingHours(); $workingHours7->setDay(Paysera_WalletApi_Entity_Location_DayWorkingHours::DAY_SUNDAY); $workingHours7->setOpeningTime(new Paysera_WalletApi_Entity_Time(0, 0)); $workingHours7->setClosingTime(new Paysera_WalletApi_Entity_Time(0, 0)); $location->setWorkingHours(array($workingHours1, $workingHours2, $workingHours4, $workingHours5, $workingHours7)); $this->assertEquals($expected, $this->service->isLocationOpen($location, $date)); }
protected function isWorkingHoursActiveByDate(Paysera_WalletApi_Entity_Location_DayWorkingHours $workingHours, DateTime $initialDate, DateTime $date) { $openingDate = clone $initialDate; $closingDate = clone $initialDate; $openingDate->setTime($workingHours->getOpeningTime()->getHours(), $workingHours->getOpeningTime()->getMinutes()); $closingDate->setTime($workingHours->getClosingTime()->getHours(), $workingHours->getClosingTime()->getMinutes()); if ($closingDate <= $openingDate) { $closingDate = $closingDate->add(new DateInterval('P1D')); } return $date >= $openingDate && $date <= $closingDate; }
/** * Encode day working hours * * @param Paysera_WalletApi_Entity_Location_DayWorkingHours $object * * @return array */ public function encodeDayWorkingHours(Paysera_WalletApi_Entity_Location_DayWorkingHours $object) { return array($object->getDay() => array('opening_time' => $this->encodeTime($object->getOpeningTime()), 'closing_time' => $this->encodeTime($object->getClosingTime()))); }