src/Entity/Common/DateTimeInterval.php line 9

  1. <?php
  2. namespace App\Entity\Common;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Embeddable]
  6. class DateTimeInterval implements DateTimeIntervalInterface
  7. {
  8.     /**
  9.      * @var DateTime|null
  10.      */
  11.     #[ORM\Column(type'datetime'nullabletrue)]
  12.     private $from;
  13.     /**
  14.      * @var  DateTime|null
  15.      */
  16.     #[ORM\Column(type'datetime'nullabletrue)]
  17.     private $to;
  18.     /**
  19.      * @return DateTime|null
  20.      */
  21.     public function getFrom(): ?DateTime
  22.     {
  23.         return $this->from;
  24.     }
  25.     /**
  26.      * @param DateTime|null $from
  27.      */
  28.     public function setFrom(?DateTime $from): void
  29.     {
  30.         $this->from $from;
  31.     }
  32.     /**
  33.      * @return DateTime|null
  34.      */
  35.     public function getTo(): ?DateTime
  36.     {
  37.         return $this->to;
  38.     }
  39.     /**
  40.      * @param DateTime|null $to
  41.      */
  42.     public function setTo(?DateTime $to): void
  43.     {
  44.         $this->to $to;
  45.     }
  46.     public function isEnded(): bool
  47.     {
  48.         if (is_null($this->to)) {
  49.             return false;
  50.         }
  51.         $now = new \DateTime();
  52.         if ($this->to <= $now) {
  53.             return true;
  54.         }
  55.         return false;
  56.     }
  57. }