diff --git a/composer.json b/composer.json index de727ad..559e68a 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "ext-json": "*", "ext-soap": "*", "guzzlehttp/guzzle": "^6.3", - "psr/log": "^1.1" + "psr/log": "^1.1", + "ext-intl": "*" }, "require-dev": { "illuminate/support": "5.1 - 5.8", diff --git a/src/Dispatching/Endpoints/PostOffices/Responses/Lunch.php b/src/Dispatching/Endpoints/PostOffices/Responses/Lunch.php index 35997b9..210cb6d 100644 --- a/src/Dispatching/Endpoints/PostOffices/Responses/Lunch.php +++ b/src/Dispatching/Endpoints/PostOffices/Responses/Lunch.php @@ -19,15 +19,14 @@ final class Lunch implements Arrayable { use DataAware; - use TimeIntervalAware; - private function getBeginValue() + protected function getBeginValue() { return $this->get('begin-lunchtime'); } - private function getEndValue() + protected function getEndValue() { return $this->get('end-lunchtime'); } diff --git a/src/Dispatching/Endpoints/PostOffices/Responses/TimeIntervalAware.php b/src/Dispatching/Endpoints/PostOffices/Responses/TimeIntervalAware.php index e076b10..3779fa6 100644 --- a/src/Dispatching/Endpoints/PostOffices/Responses/TimeIntervalAware.php +++ b/src/Dispatching/Endpoints/PostOffices/Responses/TimeIntervalAware.php @@ -25,9 +25,9 @@ public function getEnd(): ?string return $this->humanizeTime($this->getEndValue()); } - private function humanizeTime(string $time): ?string + private function humanizeTime(?string $time): ?string { - if ($this === null) { + if ($time === null) { return null; } diff --git a/src/Dispatching/Endpoints/PostOffices/Responses/WorkingHours.php b/src/Dispatching/Endpoints/PostOffices/Responses/WorkingHours.php index 7e64118..dc2ebee 100644 --- a/src/Dispatching/Endpoints/PostOffices/Responses/WorkingHours.php +++ b/src/Dispatching/Endpoints/PostOffices/Responses/WorkingHours.php @@ -25,7 +25,22 @@ final class WorkingHours implements Arrayable public function getDayNumber(): ?int { - return $this->get('weekday-id'); + return $this->get('weekday-id', 'int'); + } + + public function getDayName(?string $locale = null): ?string + { + if (null === $this->getDayNumber()) { + return null; + } + + if ($this->get('weekday-name')) { + return $this->get('weekday-name'); + } + + return (new \IntlDateFormatter( + $locale ?? 'ru_RU', \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, null, 'EEEE' + ))->format(\strtotime("next Sunday + {$this->getDayNumber()} days")); } /** @@ -36,12 +51,12 @@ public function getLunches() return Instantiator::instantiate(new ArrayOf(Lunch::class), $this->get('lunches')); } - private function getBeginValue() + protected function getBeginValue() { return $this->get('begin-worktime'); } - private function getEndValue() + protected function getEndValue() { return $this->get('end-worktime'); }