Applies the given expiry to the cookie.

@param \DateTimeInterface $date

@return self Cloned instance with the specified operation applied.

@see self::withMaxAge()
@see self::withoutExpiry()

@link https://tools.ietf.org/html/rfc6265#section-5.2.1
2621
public function withExpiry(\DateTimeInterface $date): self
    {
        $new = clone $this;

        if ($date instanceof \DateTimeImmutable) {
            $new->expiry = $date;
        } elseif ($date instanceof \DateTime) {
            $new->expiry = \DateTimeImmutable::createFromMutable($date);
        } else {
            $new->expiry = new \DateTimeImmutable("@" . $date->getTimestamp());
        }

        return $new;
    }
1264714
protected static function prepareDate($date)
    {
        if (!$date instanceof DateTimeBr) {
            $_date = DateTimeBr::createDate($date);
            if (!$_date) {
                throw new \DomainException("Tipo '$date' inváldo. Utilize DateBr.");
            }
            $date = $_date;
        }

        return $date;
    }
923031
private function expirationToDateTime($expires): DateTimeInterface
    {
        if ($expires instanceof DateTimeImmutable) {
            return $expires;
        }

        if ($expires instanceof DateInterval) {
            $expires = (new DateTime)->add($expires);
        } elseif (is_string($expires) || is_int($expires)) {
            $expires = new DateTime(is_numeric($expires) ? '@' . $expires : $expires);
        }

        if (!$expires instanceof DateTimeInterface) {
            throw new InvalidArgumentException(
                'Invalid cookie expiration time. Cannot be converted to DateTimeInterface.'
            );
        }

        return new DateTimeImmutable($expires->format(DateTime::ISO8601), $expires->getTimezone());
    }
60499
public function getExpire()
    {
        if ($this->expire instanceof DateTimeInterface) {
            return $this->expire;
        }

        return $this->expire ? $this->expire - time() : null;
    }
494405
public static function fromNative(DateTimeInterface $dateTime): Date
    {
        $year = (int) $dateTime->format('Y');
        $month = (int) $dateTime->format('n');
        $day = (int) $dateTime->format('j');

        return new static($year, $month, $day);
    }
1153876
public function setAsCache(DateTimeObject $expirationDate)
    {
        $expirationDateFormatted = date('D, d M Y H:i:s', $expirationDate->getTimestamp());

        $this->cacheControl->key('Expires', $expirationDateFormatted . ' GMT');

        $maxAge = $expirationDate->getTimestamp() - time();
        $this->cacheControl->key('Cache-Control', 'private, max-age=' . $maxAge);
        $this->cacheControl->key('Last-Modified', date('D, d M Y H:i:s') . ' GMT');

        return $this;
    }
782575
public function expiresAfter($time): CacheItemInterface
    {
        if (null === $time) {
            $this->expiry = $this->defaultLifetime > 0 ? time() + $this->defaultLifetime : null;
        } elseif ($time instanceof \DateInterval) {
            $date = \DateTime::createFromFormat('U', (string) time());
            if ($date === false) {
                throw new InvalidArgumentException('Invalid time');
            }
            $this->expiry = (int) $date->add($time)->format('U');
        } elseif (is_int($time)) {
            $this->expiry = $time + time();
        } else {
            throw new InvalidArgumentException(sprintf(
                'Expiration date must be an integer, a DateInterval or null, "%s" given',
                is_object($time) ? get_class($time) : gettype($time)
            ));
        }

        return $this;
    }
218728
public function withLastModified(DateTime $date)
    {
        $this->withoutHeader('Last-Modified');
        $this->withHeader('Last-Modified', $date->format('D, d M Y H:i:s') . ' GMT');

        return $this;
    }
128494
public function setDateTime(DateTime $date)
    {
        $this->setYear((int)$date->format('Y'));
        $this->setMonth((int)$date->format('m'));
        $this->setDay((int)$date->format('d'));

        return $this;
    }
870140
public function setExpires($date): void
    {
        if ($date instanceof \DateTime) {
            $date = clone $date;
        } else {
            $date = new \DateTime($date);
        }

        $date->setTimezone(new \DateTimeZone('UTC'));
        $this->response->setHeader('Expires', $date->format('D, d M Y H:i:s') . ' GMT');
    }
539065
public function setDateTime(\DateTimeInterface $dateTime)
    {
        if ($dateTime instanceof \DateTime) {
            $immutable = new \DateTimeImmutable('@'.$dateTime->getTimestamp());
            $dateTime = $immutable->setTimezone($dateTime->getTimezone());
        }
        $this->dateTime = $dateTime;
    }
1287163
public static function tokensExpireIn(DateTimeInterface $date = null)
    {
        if (is_null($date)) {
            return static::$tokensExpireAt
                            ? Carbon::now()->diff(static::$tokensExpireAt)
                            : new DateInterval('P1Y');
        }

        static::$tokensExpireAt = $date;

        return new static;
    }
1105708
public static function fromDateTime(\DateTimeInterface $dateTime) : LocalDate
    {
        return new LocalDate(
            (int) $dateTime->format('Y'),
            (int) $dateTime->format('n'),
            (int) $dateTime->format('j')
        );
    }
703366
public static function tokensExpireIn(DateTimeInterface $date = null, $clientId = null)
    {
        if (! $clientId) return Passport::tokensExpireIn($date);

        if (is_null($date)) {
            return isset(static::$tokensExpireAt[$clientId])
                ? Carbon::now()->diff(static::$tokensExpireAt[$clientId])
                : Passport::tokensExpireIn();
        } else {
            static::$tokensExpireAt[$clientId] = $date;
        }

        return new static;
    }
1342484
public function toDateTime($date)
    {
        if ($date instanceof \DateTimeInterface) {
            return $date;
        }

        if (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $date)) {
            return \DateTime::createFromFormat('Y-m-d', $date);
        }

        return \DateTime::createFromFormat($this->db->getQuery(true)->getDateFormat(), $date);
    }
305291
public function setDateTime(DateTimeInterface $dt)
    {
        $tz = $dt->getTimeZone();
        $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']);

        if ($isUtc) {
            $value = $dt->format('Ymd\\THis\\Z');
        } else {
            // Calculating the offset.
            $value = $dt->format('Ymd\\THisO');
        }

        $this->value = $value;
    }
36421
public function sinceAlmost(Date $date = null)
	{
		return $this->datetime->sinceAlmost(self::cast($date));
	}