Skip to content

Commit

Permalink
Ban DateTime from the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
WebMamba authored and fabpot committed Oct 9, 2022
1 parent 94be3fc commit 1a48159
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(string $name, ?string $value, string $expires = null
$this->samesite = $samesite;

if (null !== $expires) {
$timestampAsDateTime = \DateTime::createFromFormat('U', $expires);
$timestampAsDateTime = \DateTimeImmutable::createFromFormat('U', $expires);
if (false === $timestampAsDateTime) {
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires));
}
Expand All @@ -89,7 +89,7 @@ public function __toString(): string
$cookie = sprintf('%s=%s', $this->name, $this->rawValue);

if (null !== $this->expires) {
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
$dateTime = \DateTimeImmutable::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::DATE_FORMATS[0]));
}

Expand Down Expand Up @@ -202,13 +202,13 @@ private static function parseDate(string $dateValue): ?string
}

foreach (self::DATE_FORMATS as $dateFormat) {
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
if (false !== $date = \DateTimeImmutable::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
return $date->format('U');
}
}

// attempt a fallback for unusual formatting
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
if (false !== $date = date_create_immutable($dateValue, new \DateTimeZone('GMT'))) {
return $date->format('U');
}

Expand Down

0 comments on commit 1a48159

Please sign in to comment.