for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Kreemers\Period;
use DateTime;
use Kreemers\Period\Exception\EndBeforeStartException;
final class GenericPeriod
{
/**
* @var DateTime
*/
private $start;
private $end;
private function __construct(
DateTime $start,
DateTime $end
) {
$this->start = clone $start;
$this->end = clone $end;
}
public static function create(
if ($start > $end) {
throw new EndBeforeStartException();
return new static(
$start,
$end
);
public function getStart(): DateTime
return $this->start;
public function getEnd(): DateTime
return $this->end;
public function equals(GenericPeriod $period): bool
return $this->getStart() == $period->getStart()
&& $this->getEnd() == $period->getEnd();
public function in(GenericPeriod $period): bool
if ($this->getStart() >= $period->getStart()
&& $this->getStart() <= $period->getEnd()
&& $this->getEnd() >= $period->getStart()
&& $this->getEnd() <= $period->getEnd()
return true;
return false;
public function encloses(GenericPeriod $period): bool
if ($this->getStart() <= $period->getStart()
&& $this->getEnd() >= $period->getEnd()
public function intersects(GenericPeriod $period): bool
if ($this->getEnd() <= $period->getEnd()
if ($this->in($period)
|| $this->encloses($period)