Returns the next date/time <I>after</I> the given date/time which does
<I>not</I> satisfy the expression

@param \DateTime $date the date/time at which to begin the search for the next invalid date/time

@return \DateTime the next valid date/time
427166
public function getNextInvalidTimeAfter(\DateTime $date)
    {
        $difference = 1;

        $lastDate = clone $date;

        // IMPROVE THIS! The following is a BAD solution to this problem. Performance will be very bad here, depending on the cron expression. It is, however A solution.

        //keep getting the next included time until it's farther than one second
        // apart. At that point, lastDate is the last valid fire time. We return
        // the second immediately following it.
        while ($difference == 1) {
            try {
                $newDate = $this->getCronExp()->getNextRunDate($lastDate);
            } catch (\RuntimeException $e) {
                break;
            }

            $difference = ((int) $newDate->format('U')) - ((int) $lastDate->format('U'));

            if ($difference == 1) {
                $lastDate = $newDate;
            }
        }

        $lastDate->add(new \DateInterval('PT1S'));

        return $lastDate;
    }
410526
public function getStringByDate(DateTime $date)
    {
        $dateNow = new DateTime();

        if ($dateNow < $date) {
            return 'Future date not implemented.';
        }

        if ($date->format('Ymd') === $dateNow->format('Ymd')) {
            return $this->getTranslator()->trans('time.today');
        }

        if ($date->format('Ymd') === ((new DateTime('yesterday'))->format('Ymd'))) {
            return $this->getTranslator()->trans('time.yesterday');
        }

        $diffDays = ceil(($dateNow->getTimestamp() - $date->getTimestamp()) / 86400);

        if (7 > $diffDays) {
            return $this->getTranslator()->trans('time.days_ago', [
                '{days}' => $diffDays,
            ]);
        }

        if ($date->format('W') === (new DateTime('-1 Week'))->format('W')) {
            return $this->getTranslator()->trans('time.last_week');
        }

        if (28 > $diffDays) {
            return $this->getTranslator()->trans('time.weeks_ago', [
                '{weeks}' => floor($diffDays / 7),
            ]);
        }

        if ($date->format('Ym') === (new DateTime('-1 month'))->format('Ym')) {
            return $this->getTranslator()->trans('time.last_month');
        }

        if ($date->format('Y') === ($dateNow->format('Y') - 1)) {
            return $this->getTranslator()->trans('time.last_year');
        }

        return $this->getTranslator()->trans('time.years_ago', [
            '{years}' => $dateNow->format('Y') - $date->format('Y'),
        ]);
    }
380021
public function date($date)
    {
        if (! $date instanceof DateTime) {
            $date = new DateTime($date);
        }

        $this->executionYear = $date->format('Y');

        return $this->at("{$date->format('i')} {$date->format('H')} {$date->format('d')} {$date->format('m')} *");
    }
411810
protected static function convertDateTime($date)
    {
        if (!$date) {
            return;
        }

        $date = new \DateTime($date);
        $date->setTimezone(new \DateTimeZone(date_default_timezone_get()));

        return $date->format(\DateTime::ISO8601);
    }
1338813
private static function cast(Date $date = null)
	{
		if (!is_null($date))
		{
			$date = new DateTime($date);
		}

		return $date;
	}
221944
private function dateTimeToTimePoint(DateTime $date)
    {
        // missing or offset only timezone? correct to UTC
        if (!$date->getTimezone() instanceof DateTimeZone || preg_match('#^[+-]{1}[0-9]{2}:?[0-9]{2}$#', $date->getTimezone()->getName())) {
            $date->setTimezone(new DateTimeZone('UTC'));
        }

        try {
            // DateTime::createFromFormat() will create an invalid DateTimeZone object when the timezone is an offset
            // (-05:00, for example) instead of a named timezone. By recreating the DateTimeZone object, we can expose
            // this problem and ensure that a valid DateTimeZone object is always set.
            $timezone = new DateTimeZone($date->getTimezone()->getName());
        } catch (Exception $e) {
            // @codeCoverageIgnoreStart
            $date->setTimezone(new DateTimeZone('UTC'));
            // @codeCoverageIgnoreEnd
        }

        return new TimePoint(
            (int) $date->format('Y'),
            (int) $date->format('m'),
            (int) $date->format('d'),
            (int) $date->format('H'),
            (int) $date->format('i'),
            (int) $date->format('s'),
            $date->getTimezone()->getName(),
            (int) $date->format('u')
        );
    }
219998
private function parse($date, $timezone = null)
    {
        if (!($date instanceof \DateTime)) {
            if (false === strtotime($date)) {
                throw new \Exception('Invalid date not parsed.');
            }

            if (!$timezone) {
                $timezone = $this->timezoneSource;
            }

            $date = new \DateTime($date, new \DateTimeZone($timezone));
        }

        return $date;
    }
1195822
public static function get(UTCDateTime $date): DateTime
    {
        $date = $date->toDateTime();
        $date->setTimezone(new DateTimeZone(date_default_timezone_get()));

        return $date;
    }
398457
public function diff($date = 'now')
	{
		if ($date instanceof static)
			return $this->date->diff($date->date);
		else if ($date instanceof \DateTime)
			return $this->date->diff($date);
		else if (is_string($date))
			return $this->date->diff(new \DateTime($date, self::$utc));
	//	return is_string($date) ? (new \DateTime($date, self::$utc))->diff($this->date)->days : $date->diff($this->date)->days;
	}
850167
public static function convertToStartDateTime(string $date_or_date_time): \DateTime
    {
        if (strlen($date_or_date_time) <= 10) {
            return (new \DateTime($date_or_date_time))->setTime(0, 0);
        } else {
            return (new \DateTime($date_or_date_time));
        }
    }
573257
public function date($date = null)
    {
        if (is_string($date)) {
            $date = new DateTime($date);
        }

        $this->date = $date;

        return $this;
    }
709889
protected function valueToDateTime($date)
    {
        if (!$date instanceof \DateTime) {
            $date = is_int($date) ? \DateTime::createFromFormat('U', $date) : new \DateTime((string)$date);
        }
        
        return $date;
    }
695399
public function compare($date, $comparator)
  {
    //check if the argument $date is an instance of this class
    if ( $date instanceof $this){
      $tmp = $date;
    }
    else {
      $tmp = new \bbn\time($date);
    }
    switch ( $comparator ){
      case $comparator === '>':  
        return $this->get_time() > $tmp->get_time(); 
        break;
      case $comparator === '>=':  
        return $this->get_time() >= $tmp->get_time(); 
        break;
      case $comparator === '<':  
        return $this->get_time() < $tmp->get_time(); 
        break;
      case $comparator === '<=':  
        return $this->get_time() <= $tmp->get_time(); 
        break;
      case $comparator === '=':  
        return $this->get_time() == $tmp->get_time(); 
        break;
    }
  }
1075073
protected function formatDateTime(\DateTime $date = null, $format = null)
    {
        return $date && $format ?
            $date->format($format) :
            $date
        ;
    }
1018951
public function dateIsEarlier(\DateTime $date) {
    $dateEarlier = FALSE;

    $t1 = $this->start_date->getTimeStamp();

    $t3 = $date->getTimeStamp();

    if ($t3 < $t1) {
      $dateEarlier = TRUE;
    }

    return $dateEarlier;
  }
649239
public static function inFuture($date, $time = null)
    {
        if (is_null($time)) {
            $time = self::time();
        }
        if (!is_int($date)) {
            $date = self::strtotime($date);
        }

        return $time < $date;
    }
695058
protected function convertToSqlDateTime($date)
    {
        if ($date instanceof \DateTime) {
            $date = $this->expr()->literal($date->format(self::SQL_DATE_TIME));
        }

        return $date;
    }