diff --git a/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php b/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php index cb27197f9ee87..7bc85e522613b 100644 --- a/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php +++ b/src/Symfony/Component/RateLimiter/Policy/SlidingWindow.php @@ -122,6 +122,6 @@ public function getHitCount(): int public function getRetryAfter(): \DateTimeImmutable { - return \DateTimeImmutable::createFromFormat('U.u', $this->windowEndAt); + return \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', $this->windowEndAt)); } } diff --git a/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php b/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php index f81784706c185..df1d01499679b 100644 --- a/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php +++ b/src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowTest.php @@ -102,4 +102,13 @@ public function testGetRetryAfterUsesMicrotime() // should be 500ms left (10 - 9.5) $this->assertEqualsWithDelta(0.5, $window->getRetryAfter()->format('U.u') - microtime(true), 0.2); } + + public function testCreateAtExactTime() + { + ClockMock::register(SlidingWindow::class); + ClockMock::withClockMock(1234567890.000000); + $window = new SlidingWindow('foo', 10); + $window->getRetryAfter(); + $this->assertEquals('1234567900.000000', $window->getRetryAfter()->format('U.u')); + } }