Skip to content

Commit

Permalink
rename period
Browse files Browse the repository at this point in the history
  • Loading branch information
cevro committed Mar 20, 2024
1 parent 4cbcbeb commit 227fe7b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/DateTime/DateTimePeriod.php → src/DateTime/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,31 @@

namespace Fykosak\Utils\DateTime;

class DateTimePeriod
class Period
{
public function __construct(
public readonly \DateTimeImmutable $begin,
public readonly \DateTimeImmutable $end,
) {
if ($this->begin->getTimestamp() > $this->end->getTimestamp()) {
if ($this->begin > $this->end) {
throw new \LogicException();
}
}

public function isBefore(?\DateTimeInterface $dateTime = null): bool
{
$timeStamp = $dateTime ? $dateTime->getTimestamp() : time();
return $this->begin->getTimestamp() > $timeStamp;
return $this->begin > ($dateTime ?? new \DateTimeImmutable());
}

public function isAfter(?\DateTimeInterface $dateTime = null): bool
{
$timeStamp = $dateTime ? $dateTime->getTimestamp() : time();
return $this->end->getTimestamp() < $timeStamp;
return $this->end < ($dateTime ?? new \DateTimeImmutable());
}

public function isOnGoing(?\DateTimeInterface $dateTime = null): bool
{
$timeStamp = $dateTime ? $dateTime->getTimestamp() : time();
return $this->begin->getTimestamp() <= $timeStamp
&& $this->end->getTimestamp() >= $timeStamp;
return $this->begin <= ($dateTime ?? new \DateTimeImmutable())
&& $this->end >= ($dateTime ?? new \DateTimeImmutable());
}

public function is(Phase $period, ?\DateTimeInterface $dateTime = null): bool
Expand Down

0 comments on commit 227fe7b

Please sign in to comment.