refactor: use epoch timestamp
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -9,32 +9,30 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXF\Resource\Range;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
interface IRangeDate extends IRange {
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getStart(): DateTimeInterface;
|
||||
public function getStart(): int;
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setStart(DateTimeInterface $value): void;
|
||||
public function setStart(int $value): void;
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEnd(): DateTimeInterface;
|
||||
public function getEnd(): int;
|
||||
|
||||
/**
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setEnd(DateTimeInterface $value): void;
|
||||
public function setEnd(int $value): void;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,13 +9,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXF\Resource\Range;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use KTXF\Utile\Timestamp;
|
||||
|
||||
class RangeDate extends Range implements IRangeDate {
|
||||
|
||||
protected DateTimeInterface $start;
|
||||
protected DateTimeInterface $end;
|
||||
protected int $start;
|
||||
protected int $end;
|
||||
|
||||
public function jsonDeserialize(array|string $data): static {
|
||||
if (is_string($data)) {
|
||||
@@ -23,10 +22,16 @@ class RangeDate extends Range implements IRangeDate {
|
||||
}
|
||||
|
||||
if (isset($data['start'])) {
|
||||
$this->setStart(new DateTimeImmutable($data['start']));
|
||||
$start = Timestamp::normalize($data['start']);
|
||||
if ($start !== null) {
|
||||
$this->setStart($start);
|
||||
}
|
||||
}
|
||||
if (isset($data['end'])) {
|
||||
$this->setEnd(new DateTimeImmutable($data['end']));
|
||||
$end = Timestamp::normalize($data['end']);
|
||||
if ($end !== null) {
|
||||
$this->setEnd($end);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -46,7 +51,7 @@ class RangeDate extends Range implements IRangeDate {
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getStart(): DateTimeInterface {
|
||||
public function getStart(): int {
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
@@ -55,7 +60,7 @@ class RangeDate extends Range implements IRangeDate {
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setStart(DateTimeInterface $value): void {
|
||||
public function setStart(int $value): void {
|
||||
$this->start = $value;
|
||||
}
|
||||
|
||||
@@ -64,7 +69,7 @@ class RangeDate extends Range implements IRangeDate {
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEnd(): DateTimeInterface {
|
||||
public function getEnd(): int {
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
@@ -73,7 +78,7 @@ class RangeDate extends Range implements IRangeDate {
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setEnd(DateTimeInterface $value): void {
|
||||
public function setEnd(int $value): void {
|
||||
$this->end = $value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user