1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of RussianPost SDK package. |
5
|
|
|
* |
6
|
|
|
* © Appwilio (http://appwilio.com), JhaoDa (https://github.com/jhaoda) |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\PostOffices\Responses; |
15
|
|
|
|
16
|
|
|
use Appwilio\RussianPostSDK\Dispatching\DataAware; |
17
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Instantiator; |
18
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Http\ArrayOf; |
19
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
20
|
|
|
|
21
|
|
|
final class WorkingHours implements Arrayable |
22
|
|
|
{ |
23
|
|
|
use DataAware; |
24
|
|
|
use TimeIntervalAware; |
25
|
|
|
|
26
|
|
|
public function getDayNumber(): ?int |
27
|
|
|
{ |
28
|
|
|
return $this->get('weekday-id', 'int'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function getDayName(?string $locale = null): ?string |
32
|
|
|
{ |
33
|
|
|
if (null === $this->getDayNumber()) { |
34
|
|
|
return null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if ($this->get('weekday-name')) { |
38
|
|
|
return $this->get('weekday-name'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return (new \IntlDateFormatter( |
42
|
|
|
$locale ?? 'ru_RU', \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, null, 'EEEE' |
43
|
|
|
))->format(\strtotime("next Sunday + {$this->getDayNumber()} days")); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return Lunch[]|null |
48
|
|
|
*/ |
49
|
|
|
public function getLunches() |
50
|
|
|
{ |
51
|
|
|
return Instantiator::instantiate(new ArrayOf(Lunch::class), $this->get('lunches')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function getBeginValue() |
55
|
|
|
{ |
56
|
|
|
return $this->get('begin-worktime'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function getEndValue() |
60
|
|
|
{ |
61
|
|
|
return $this->get('end-worktime'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|