Returns whether the supplied date time is within (inclusive) the date time range.

@param DateTime $dateTime

@return bool
762983
public function contains(DateTime $dateTime) : bool
    {
        return $this->start->comesBeforeOrEqual($dateTime) && $this->end->comesAfterOrEqual($dateTime);
    }
962046
public function endsLater(\DateTime $date) {
    $later = FALSE;

    $t2 = $this->end_date->getTimeStamp();

    $t4 = $date->getTimestamp();

    if ($t2 > $t4) {
      $later = TRUE;
    }

    return $later;
  }
487403
private function validateTimezone(DateTime $dateTime)
    {
        $dateTime = Carbon::instance($dateTime);

        // Make sure we have the proper timezone. This is to prevent a developer accidentally removing more than they
        // expect to remove
        if ($dateTime->getTimezone()->getName() !== 'UTC') {
            throw new \InvalidArgumentException('Passed datetime is not in UTC timezone.');
        }

        return $dateTime;
    }
1055791
public function startOfWeek(\DateTime $datetime)
	{
		$diffInDays = intval($datetime->format('N')) - 1;
		$intervalSpec = sprintf('P%sD', $diffInDays);

		$datetime->sub(new \DateInterval($intervalSpec));
	}
140936
public function findInvalid($datetime = null)
    {
        $datetime = (null === $datetime) ? new \DateTime() : $datetime;

        $queryBuilder = $this->createQueryBuilder()
            ->field('valid')->lt($datetime);

        return $queryBuilder->getQuery()->execute();
    }
136950
public static function fromDateTime(DateTime $dateTime)
    {
        $dateTime = clone $dateTime;

        return new static($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp());
    }
398185
final public function hasPassed(DateTime $dateTime = null)
    {
        $dateTime = $dateTime ?: DateTime::createFromFormat("U.u", $this->unixTimestampAsUuFormat(microtime(true)));
        return $this->value < $dateTime;
    }
1271928
public function getEndTimeFromStartTime(\DateTime $startTime)
    {
        $endTime  = clone $startTime;
        $endTime->add(\DateInterval::createFromDateString('+2 hour'));

        return $endTime;
    }
297528
public static function isDue($pattern, \DateTime $time = null)
  {
    if($time === null)
    {
      $time = new \DateTime();
    }
    // trim time back to last round minute
    $time->setTime($time->format('H'), $time->format('i'));

    $expression = Expression::createFromPattern($pattern);

    foreach(self::$_formats as $pos => $fmt)
    {
      if($pos > 4 && !isset($expression[$pos]))
      {
        continue;
      }

      $cmp = intval($time->format($fmt));

      $posSuccess = false;
      foreach($expression[$pos] as $part)
      {
        if($part['full'] == '*' || $part['full'] == $cmp || $posSuccess)
        {
          $posSuccess = true;
          break;
        }

        // process order: range, modulus

        // doesn't match val
        if(isset($part['val']) && $part['val'] != '*' && $cmp != $part['val'])
        {
          continue;
        }

        // out of range
        if(isset($part['min']) && isset($part['max']) && ($cmp < $part['min'] || $cmp > $part['max']))
        {
          continue;
        }

        $offset = isset($part['min']) ? $part['min'] : 0;
        if(isset($part['mod']) && (($cmp - $offset) % $part['mod']) != 0)
        {
          continue;
        }

        $posSuccess = true;
      }
      if(!$posSuccess)
      {
        return false;
      }
    }
    return true;
  }
200161
public function findEndBefore(\DateTime $dateTime)
    {
        return $this->createQueryBuilder('t')
            ->where('t.lastExecution IS NULL OR t.lastExecution > :dateTime')
            ->setParameter('dateTime', $dateTime)
            ->getQuery()
            ->getResult();
    }
1300624
private function _processDateTime($dateTime)
    {
        if (is_numeric($dateTime)) {
            $timestamp = $dateTime;
            $dateTime = new \DateTime();
            $dateTime->setTimestamp($timestamp);
        } elseif (empty($dateTime)) {
            throw new \InvalidArgumentException('Date/time is empty');
        } elseif (is_string($dateTime)) {
            $dateTime = new \DateTime($dateTime);
        }

        if (!($dateTime instanceof \DateTime)) {
            throw new \InvalidArgumentException('Incorrect date/time type');
        }
        return $dateTime;
    }
496442
private function isDatetime($dateTime)
    {
        if (preg_match('/^(\d{4})-(\d\d?)-(\d\d?) (\d\d?):(\d\d?):(\d\d?)$/', $dateTime, $matches)) {
            return checkdate($matches[2], $matches[3], $matches[1]) && $matches[4] / 24 < 1 && $matches[5] / 60 < 1 && $matches[6] / 60 < 1;
        }
        return false;
    }
424013
def is_within_hour_range(ref_time, start_time, end_time):
    
    str_ref_time = ref_time.strftime('%Y%m%d')
    start_time_ = mktime(strptime(str_ref_time + '-' + start_time, '%Y%m%d-%H:%M'))
    end_time_ = mktime(strptime(str_ref_time + '-' + end_time, '%Y%m%d-%H:%M'))
    ref_time_ = mktime(ref_time.timetuple())
    if start_time_ <= ref_time_ <= end_time_:
        return True
    else:
        return False
1108037
public function writeDateTime(DateTime $dateTime)
    {
        try {
            $timeStamp = $dateTime->getTimestamp();
            $this->getStream()->write(pack('l', $timeStamp));
        } catch (StreamException $e) {
            $this->handleStreamException($e, BinaryStreamAccessException::DATETIME, false);
        }
    }
530290
private function getDateBefore(\DateTime $date)
    {
        $tmpDate = clone $date;
        $tmpDate->modify('-1 day');

        $dayOfWeek = (int) $tmpDate->format('N');
        $closestDay = $this->getClosestDayBefore($dayOfWeek);

        if ($closestDay->getDayOfWeek() !== $dayOfWeek) {
            $tmpDate->modify(sprintf('last %s', Days::toString($closestDay->getDayOfWeek())));
        }

        return $tmpDate;
    }
298787
public static function getDateTime($datetime = null)
    {
        if ($datetime instanceof \DateTime) {
            return clone $datetime;
        }
        if ($datetime instanceof \DateTimeImmutable) {
            return new \DateTime($datetime->format(\DateTime::ATOM));
        }
        if (\is_string($datetime)) {
            if (\is_numeric($datetime)) {
                /*
                    check if datetime is an int of the the form YYYYMMDD or YYYYMMDDHHMMSS
                    Debug::_log('datetime', $datetime)
                */
                $isTs = !preg_match('/^(19|20)\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\d|2[0-3])\d[0-5]\d[0-5]\d)?$/', $datetime);
                if ($isTs) {
                    $datetime = '@'.$datetime;
                }
            }
            Debug::_log('datetime', $datetime);
            return new \DateTime($datetime);
        }
        if (\is_int($datetime) || \is_float($datetime)) {
            $dateTime = new \DateTime();
            $dateTime->setTimestamp($datetime);
            return $dateTime;
        }
        return new \DateTime();
    }
195365
def contains(self, time: datetime.datetime,
                 inclusive: bool = True) -> bool:
        
        if inclusive:
            return self.start <= time <= self.end
        else:
            return self.start < time < self.end