diff --git a/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/DateTimeValueResolver.php b/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/DateTimeValueResolver.php index a73a7e1b47a27..0cfd42badc974 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/DateTimeValueResolver.php +++ b/src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/DateTimeValueResolver.php @@ -73,7 +73,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array } if (null !== $format) { - $date = $class::createFromFormat($format, $value); + $date = $class::createFromFormat($format, $value, $this->clock?->now()->getTimeZone()); if (($class::getLastErrors() ?: ['warning_count' => 0])['warning_count']) { $date = false; @@ -83,7 +83,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array $value = '@'.$value; } try { - $date = new $class($value); + $date = new $class($value, $this->clock?->now()->getTimeZone()); } catch (\Exception) { $date = false; } diff --git a/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/DateTimeValueResolverTest.php b/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/DateTimeValueResolverTest.php index c56cbeb5e335f..6529ca9f7640b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/DateTimeValueResolverTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Controller/ArgumentResolver/DateTimeValueResolverTest.php @@ -84,8 +84,8 @@ public function testUnsupportedArgument() */ public function testFullDate(string $timezone, bool $withClock) { - date_default_timezone_set($timezone); - $resolver = new DateTimeValueResolver($withClock ? new MockClock() : null); + date_default_timezone_set($withClock ? 'UTC' : $timezone); + $resolver = new DateTimeValueResolver($withClock ? new MockClock('now', $timezone) : null); $argument = new ArgumentMetadata('dummy', \DateTimeImmutable::class, false, false, null); $request = self::requestWithAttributes(['dummy' => '2012-07-21 00:00:00']); @@ -103,7 +103,7 @@ public function testFullDate(string $timezone, bool $withClock) */ public function testUnixTimestamp(string $timezone, bool $withClock) { - date_default_timezone_set($timezone); + date_default_timezone_set($withClock ? 'UTC' : $timezone); $resolver = new DateTimeValueResolver($withClock ? new MockClock('now', $timezone) : null); $argument = new ArgumentMetadata('dummy', \DateTimeImmutable::class, false, false, null); @@ -212,7 +212,7 @@ public function testCustomClass() */ public function testDateTimeImmutable(string $timezone, bool $withClock) { - date_default_timezone_set($timezone); + date_default_timezone_set($withClock ? 'UTC' : $timezone); $resolver = new DateTimeValueResolver($withClock ? new MockClock('now', $timezone) : null); $argument = new ArgumentMetadata('dummy', \DateTimeImmutable::class, false, false, null); @@ -231,7 +231,7 @@ public function testDateTimeImmutable(string $timezone, bool $withClock) */ public function testWithFormat(string $timezone, bool $withClock) { - date_default_timezone_set($timezone); + date_default_timezone_set($withClock ? 'UTC' : $timezone); $resolver = new DateTimeValueResolver($withClock ? new MockClock('now', $timezone) : null); $argument = new ArgumentMetadata('dummy', \DateTimeInterface::class, false, false, null, false, [