-
Notifications
You must be signed in to change notification settings - Fork 19
/
SupplyDelay.php
61 lines (50 loc) · 1.39 KB
/
SupplyDelay.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php declare(strict_types=1);
namespace MpApiClient\SupplyDelay\Entity;
use DateTime;
use DateTimeInterface;
use Exception;
use JsonSerializable;
use MpApiClient\Common\Util\InputDataUtil;
use MpApiClient\Common\Util\JsonSerializeEntityTrait;
final class SupplyDelay implements JsonSerializable
{
use JsonSerializeEntityTrait;
private DateTimeInterface $validFrom;
private DateTimeInterface $validTo;
public function __construct(DateTimeInterface $validFrom, DateTimeInterface $validTo)
{
$this->validFrom = $validFrom;
$this->validTo = $validTo;
}
/**
* @param array<string, mixed> $data
*
* @throws Exception
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
new DateTime($data['valid_from']),
new DateTime($data['valid_to']),
);
}
/**
* @return array<string, mixed>
*/
public function getArrayForApi(): array
{
return [
'valid_from' => $this->getValidFrom()->format(InputDataUtil::DATE_TIME_FORMAT),
'valid_to' => $this->getValidTo()->format(InputDataUtil::DATE_TIME_FORMAT),
];
}
public function getValidFrom(): DateTimeInterface
{
return $this->validFrom;
}
public function getValidTo(): DateTimeInterface
{
return $this->validTo;
}
}