feat: add deserilazation

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-03 21:33:28 -04:00
parent 8f61c4d2d5
commit fe78426a5d
4 changed files with 41 additions and 2 deletions
+16 -1
View File
@@ -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
*