commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
EstimatedDeliveryModel.php
1<?php
2
3declare(strict_types=1);
10
15use DateTimeImmutable;
16use stdClass;
17
22{
27 protected $from;
28
33 protected $until;
34
35
39 public function __construct(
40 ?DateTimeImmutable $from = null,
41 ?DateTimeImmutable $until = null
42 ) {
43 $this->from = $from;
44 $this->until = $until;
45 }
46
53 public function getFrom()
54 {
55 if (is_null($this->from)) {
57 $data = $this->raw(self::FIELD_FROM);
58 if (is_null($data)) {
59 return null;
60 }
61 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
62 if (false === $data) {
63 return null;
64 }
65 $this->from = $data;
66 }
67
68 return $this->from;
69 }
70
78 public function getUntil()
79 {
80 if (is_null($this->until)) {
82 $data = $this->raw(self::FIELD_UNTIL);
83 if (is_null($data)) {
84 return null;
85 }
86 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
87 if (false === $data) {
88 return null;
89 }
90 $this->until = $data;
91 }
92
93 return $this->until;
94 }
95
96
100 public function setFrom(?DateTimeImmutable $from): void
101 {
102 $this->from = $from;
103 }
104
108 public function setUntil(?DateTimeImmutable $until): void
109 {
110 $this->until = $until;
111 }
112
113
114 #[\ReturnTypeWillChange]
115 public function jsonSerialize()
116 {
117 $data = $this->toArray();
118 if (isset($data[EstimatedDelivery::FIELD_FROM]) && $data[EstimatedDelivery::FIELD_FROM] instanceof \DateTimeImmutable) {
119 $data[EstimatedDelivery::FIELD_FROM] = $data[EstimatedDelivery::FIELD_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
120 }
121
122 if (isset($data[EstimatedDelivery::FIELD_UNTIL]) && $data[EstimatedDelivery::FIELD_UNTIL] instanceof \DateTimeImmutable) {
123 $data[EstimatedDelivery::FIELD_UNTIL] = $data[EstimatedDelivery::FIELD_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
124 }
125 return (object) $data;
126 }
127}
__construct(?DateTimeImmutable $from=null, ?DateTimeImmutable $until=null)