From ab69a0bd22c6551c3e9061e4a022ad0ea8de51fc Mon Sep 17 00:00:00 2001 From: Doug Wright Date: Wed, 24 Aug 2016 17:17:51 +0100 Subject: [PATCH] [HttpFoundation] added support for \DateTimeImmutable in setters Backwards compatibility is assured by typehinting for DateTimeInterface, and converting to \DateTime for onward use --- .../Component/HttpFoundation/Response.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index d4584ed17c494..c712040614bea 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -626,12 +626,13 @@ public function getDate() /** * Sets the Date header. * - * @param \DateTime $date A \DateTime instance + * @param \DateTimeInterface $date A \DateTimeInterface instance * * @return Response */ - public function setDate(\DateTime $date) + public function setDate(\DateTimeInterface $date) { + $date = \DateTime::createFromFormat(\DateTime::ISO8601, $date->format(\DateTime::ISO8601)); $date->setTimezone(new \DateTimeZone('UTC')); $this->headers->set('Date', $date->format('D, d M Y H:i:s').' GMT'); @@ -686,16 +687,16 @@ public function getExpires() * * Passing null as value will remove the header. * - * @param \DateTime|null $date A \DateTime instance or null to remove the header + * @param \DateTimeInterface|null $date A \DateTimeInterface instance or null to remove the header * * @return Response */ - public function setExpires(\DateTime $date = null) + public function setExpires(\DateTimeInterface $date = null) { if (null === $date) { $this->headers->remove('Expires'); } else { - $date = clone $date; + $date = \DateTime::createFromFormat(\DateTime::ISO8601, $date->format(\DateTime::ISO8601)); $date->setTimezone(new \DateTimeZone('UTC')); $this->headers->set('Expires', $date->format('D, d M Y H:i:s').' GMT'); } @@ -826,16 +827,16 @@ public function getLastModified() * * Passing null as value will remove the header. * - * @param \DateTime|null $date A \DateTime instance or null to remove the header + * @param \DateTimeInterface|null $date A \DateTimeInterface instance or null to remove the header * * @return Response */ - public function setLastModified(\DateTime $date = null) + public function setLastModified(\DateTimeInterface $date = null) { if (null === $date) { $this->headers->remove('Last-Modified'); } else { - $date = clone $date; + $date = \DateTime::createFromFormat(\DateTime::ISO8601, $date->format(\DateTime::ISO8601)); $date->setTimezone(new \DateTimeZone('UTC')); $this->headers->set('Last-Modified', $date->format('D, d M Y H:i:s').' GMT'); }