Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HeaderBag.php

function HeaderBag::getDate

Returns the HTTP header value converted to a date.

Throws

\RuntimeException When the HTTP header is not parseable

File

vendor/symfony/http-foundation/HeaderBag.php, line 190

Class

HeaderBag
HeaderBag is a container for HTTP headers.

Namespace

Symfony\Component\HttpFoundation

Code

public function getDate(string $key, ?\DateTimeInterface $default = null) : ?\DateTimeImmutable {
    if (null === ($value = $this->get($key))) {
        return null !== $default ? \DateTimeImmutable::createFromInterface($default) : null;
    }
    if (false === ($date = \DateTimeImmutable::createFromFormat(\DATE_RFC2822, $value))) {
        throw new \RuntimeException(\sprintf('The "%s" HTTP header is not parseable (%s).', $key, $value));
    }
    return $date;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal