You are here

public function Period::contains in Recurring Time Period 8

Checks whether the given date/time is contained in the period.

Parameters

\\DateTimeImmutable $date: The date/time.

Return value

bool TRUE if the date/time is contained in the period, FALSE otherwise.

File

src/DateTime/Period.php, line 149

Class

Period
Represents a period of time with specific start and end dates.

Namespace

Drupal\recurring_period\Datetime

Code

public function contains(\DateTimeImmutable $date) {

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