public function HeaderBag::getDate

Returns the HTTP header value converted to a date.

@api

Parameters

string $key The parameter key:

\DateTime $default The default value:

Return value

\DateTime The filtered value

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/HeaderBag.php, line 230

Class

HeaderBag
HeaderBag is a container for HTTP headers.

Namespace

Symfony\Component\HttpFoundation

Code

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