58a9c4351d
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
86 lines
1.4 KiB
PHP
86 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXF\Resource\Range;
|
|
|
|
use KTXF\Utile\Timestamp;
|
|
|
|
class RangeDate extends Range implements IRangeDate {
|
|
|
|
protected int $start;
|
|
protected int $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'])) {
|
|
$start = Timestamp::normalize($data['start']);
|
|
if ($start !== null) {
|
|
$this->setStart($start);
|
|
}
|
|
}
|
|
if (isset($data['end'])) {
|
|
$end = Timestamp::normalize($data['end']);
|
|
if ($end !== null) {
|
|
$this->setEnd($end);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Returns the type of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function type(): RangeType {
|
|
return RangeType::DATE;
|
|
}
|
|
|
|
/**
|
|
* Gets the start date of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getStart(): int {
|
|
return $this->start;
|
|
}
|
|
|
|
/**
|
|
* Sets the start date of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setStart(int $value): void {
|
|
$this->start = $value;
|
|
}
|
|
|
|
/**
|
|
* Gets the end date of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function getEnd(): int {
|
|
return $this->end;
|
|
}
|
|
|
|
/**
|
|
* Sets the end date of the range
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
public function setEnd(int $value): void {
|
|
$this->end = $value;
|
|
}
|
|
|
|
}
|