@param \DateTime|null $date_premiere

@return Search
514888
public function setDatePremiere(\DateTime $date_premiere = null)
    {
        $this->date_premiere = $date_premiere ? clone $date_premiere : $date_premiere;

        return $this;
    }
247102
private function getClosestDateAfter(\DateTime $date)
    {
        $tmpDate = clone $date;
        $dayOfWeek = (int) $tmpDate->format('N');
        $time = Time::fromDate($tmpDate);

        if (!$this->holidays->isHoliday($tmpDate) && null !== $day = $this->getDay($dayOfWeek)) {
            if (null !== $closestTime = $day->getClosestOpeningTimeAfter($time, $tmpDate)) {
                $tmpDate->setTime($closestTime->getHours(), $closestTime->getMinutes(), $closestTime->getSeconds());

                return $tmpDate;
            }
        }

        $tmpDate = $this->getDateAfter($tmpDate);

        while ($this->holidays->isHoliday($tmpDate)) {
            $tmpDate = $this->getDateAfter($tmpDate);
        }

        $closestDay = $this->getClosestDayBefore((int) $tmpDate->format('N'));
        $closingTime = $closestDay->getOpeningTime($tmpDate);
        $tmpDate->setTime($closingTime->getHours(), $closingTime->getMinutes(), $closingTime->getSeconds());

        return $tmpDate;
    }
454479
public function getTargetAvailableDate(): \Lullabot\Mpx\DataService\DateTime\DateTimeFormatInterface
    {
        if (!$this->targetAvailableDate) {
            return new NullDateTime();
        }

        return $this->targetAvailableDate;
    }
250190
public static function compare($date1, $date2, $operator = null)
    {
        $date1 = $date1 instanceof \DateTimeInterface ? $date1 : new \DateTime($date1);
        $date2 = $date2 instanceof \DateTimeInterface ? $date2 : new \DateTime($date2);

        if ($operator === null) {
            if ($date1 == $date2) {
                return 0;
            }

            return (int) ($date1 < $date2);
        }

        switch ((string) $operator) {
            case '=':
                return $date1 == $date2;
            case '!=':
                return $date1 != $date2;
            case '>':
            case 'gt':
                return $date1 > $date2;
            case '>=':
            case 'gte':
                return $date1 >= $date2;
            case '<':
            case 'lt':
                return $date1 < $date2;
            case '<=':
            case 'lte':
                return $date1 <= $date2;
        }

        throw new \InvalidArgumentException('Invalid operator: ' . $operator);
    }
36421
public function sinceAlmost(Date $date = null)
	{
		return $this->datetime->sinceAlmost(self::cast($date));
	}
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;
    }
493489
private function matchesRelativeDate(\DateTime $date, $prefix)
    {
        $correctDate = new \DateTime($prefix . ' ' . $date->format('D') . ' of ' . $date->format('F') . ' ' . $date->format('Y'));

        return $date->format('Y-m-d') == $correctDate->format('Y-m-d');
    }
761497
public function setStartDate($date)
    {
        $date = AnDomainAttributeDate::getInstance()->setDate($date);
        $this->set('startDate', $date);

        return $this;
    }
941445
public function set_uploaded_on(DateTime $date = null)
    {
        $this->uploaded_on = $date;
        $this->updated_on = new DateTime();

        $sql = 'UPDATE bridge_elements
            SET uploaded_on = :uploaded_on, updated_on = :update WHERE id = :id';

        $params = [
            ':uploaded_on' => NullableDateTime::format($this->uploaded_on, DATE_ISO8601),
            ':id' => $this->id,
            ':update' => $this->updated_on->format(DATE_ISO8601),
        ];

        $stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql);
        $stmt->execute($params);
        $stmt->closeCursor();

        return $this;
    }
984115
public function setDateEnd(\DateTime $date_end = null)
    {
        $this->date_end = $date_end ? clone $date_end : null;

        return $this;
    }
794638
public static function normalize(\DateTime $date = null)
    {
        if (!empty($date)) {
            return $date->format(static::DATE_FORMAT);
        }

        return null;
    }
497613
public function getDateTime(string $date, string $pattern = "Y-m-d H:i:s")
    {
        if (!$date)
            $this->data = date($pattern);
        else
            $this->prepareDateTime($date);

        if($this->erro || !isset($this->data['ano']) || !isset($this->data['mes']) || !isset($this->data['dia'])) {
            return null;
        } else {
            $strtoTime = "";
            if (isset($this->data['h']) && $this->data['h'] > 11) {
                $this->data['h'] -= 12;
                $strtoTime = "+12hours";
            }

            $originalDate = $this->data['ano'] . '-' . $this->data['mes'] . '-' . $this->data['dia'] . " " . ($this->data['h'] ?? 0) . ":" . ($this->data['i'] ?? 0) . ":" . ($this->data['s'] ?? 0);
            return date($pattern, strtotime($originalDate . $strtoTime));
        }
    }
985070
public static function dateNow($default_format = null)
    {
        $now = new \DateTime();

        if (is_null($default_format)) {
            $default_format = Grav::instance()['config']->get('system.pages.dateformat.default');
        }

        return $now->format($default_format);
    }
576759
public function createSearch( $default = false )
	{
		if( $default === true )
		{
			$curDate = date( 'Y-m-d H:i:00', time() );
			$object = $this->_createSearch( 'product' );

			$expr = array( $object->getConditions() );

			$temp = array(
				$object->compare( '==', 'product.datestart', null ),
				$object->compare( '<=', 'product.datestart', $curDate ),
			);
			$expr[] = $object->combine( '||', $temp );

			$temp = array(
				$object->compare( '==', 'product.dateend', null ),
				$object->compare( '>=', 'product.dateend', $curDate ),
			);
			$expr[] = $object->combine( '||', $temp );

			$object->setConditions( $object->combine( '&&', $expr ) );

			return $object;
		}

		return parent::createSearch();
	}
1303430
final public static function cloneDateTime($date)
    {
        try {
            $result = new \DateTimeImmutable();
            return $result->setTimezone($date->getTimezone())->setTimestamp($date->getTimestamp());
        } catch (\Exception $e) {
            return null;
        }
    }
96028
public function filterByApprovedBefore(\DateTime $date)
    {
        $this->query->andWhere(
             'cv.cvDateApproved <= ' . $this->query->createNamedParameter($date->format('Y-m-d H:i-s'))
        );
    }
293190
public function sortByStartDate()
	{
		uksort( $this->contexts, function( $a, $b ) use ( &$contexts )
		{
			return -1 * strcmp( $this->contexts[ $a] ['period']['startDate'], $this->contexts[ $b]['period']['startDate'] );
		} );

		return $this;
	}