You are here

public function PeriodEntityTrait::contains in Recurring Time Period 8

Implements \Drupal\recurring_period\Entity\PeriodEntityInterface::contains().

File

src/Entity/PeriodEntityTrait.php, line 70

Class

PeriodEntityTrait
Provides base fields and accessors for entities that represent a time period.

Namespace

Drupal\recurring_period\Entity

Code

public function contains(DrupalDateTime $date) {

  // Unlike DateTime, DrupalDateTime objects can't be compared directly.
  $timestamp = $date
    ->format('U');
  $starts = $this
    ->getStartDate()
    ->format('U');
  $ends = $this
    ->getEndDate()
    ->format('U');
  return $timestamp >= $starts && $timestamp < $ends;
}