feat: add deserilazation
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXF\Resource\Range;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
|
||||
class RangeDate extends Range implements IRangeDate {
|
||||
@@ -17,6 +17,21 @@ class RangeDate extends Range implements IRangeDate {
|
||||
protected DateTimeInterface $start;
|
||||
protected DateTimeInterface $end;
|
||||
|
||||
public function jsonDeserialize(array|string $data): static {
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true, flags: JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
if (isset($data['start'])) {
|
||||
$this->setStart(new DateTimeImmutable($data['start']));
|
||||
}
|
||||
if (isset($data['end'])) {
|
||||
$this->setEnd(new DateTimeImmutable($data['end']));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the range
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user