You are here

private static function Cookie::parseDate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/browser-kit/Cookie.php \Symfony\Component\BrowserKit\Cookie::parseDate()
1 call to Cookie::parseDate()
Cookie::fromString in vendor/symfony/browser-kit/Cookie.php
Creates a Cookie instance from a Set-Cookie header value.

File

vendor/symfony/browser-kit/Cookie.php, line 199

Class

Cookie
Cookie represents an HTTP cookie.

Namespace

Symfony\Component\BrowserKit

Code

private static function parseDate($dateValue) {

  // trim single quotes around date if present
  if (($length = strlen($dateValue)) > 1 && "'" === $dateValue[0] && "'" === $dateValue[$length - 1]) {
    $dateValue = substr($dateValue, 1, -1);
  }
  foreach (self::$dateFormats as $dateFormat) {
    if (false !== ($date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT')))) {
      return $date
        ->getTimestamp();
    }
  }

  // attempt a fallback for unusual formatting
  if (false !== ($date = date_create($dateValue, new \DateTimeZone('GMT')))) {
    return $date
      ->getTimestamp();
  }
  throw new \InvalidArgumentException(sprintf('Could not parse date "%s".', $dateValue));
}