Closed
Description
Symfony version(s) affected
6.4.5
Description
PHP: 8.1
The DatePoint class extends DateTimeImmutable, so you can use it in your code anywhere a DateTimeImmutable or DateTimeInterface is expected.
I would expect that the behavior of DatePoint does not differ from DateTimeImmutable to use as a pure replacement. However, I cannot use it as it is everywhere (including in test cases) because creating a date with a fixed date keep the current time.
See the repro below.
How to reproduce
<?php
$datePoint = new \Symfony\Component\Clock\DatePoint('2024-01-01');
$immutableDate = new \DateTimeImmutable('2024-01-01');
\PHPUnit\Framework\Assert::assertEquals('2024-01-01 00:00:00', $immutableDate->format('Y-m-d H:i:s')); // Pass
\PHPUnit\Framework\Assert::assertEquals('2024-01-01 00:00:00', $datePoint->format('Y-m-d H:i:s')); // Fails
Possible Solution
- Add documentation about the different behavior and that DatePoint differs from DateTimeImmutable (not a pure replacement)
- Or introduce a named constructor keep the different behavior and leave the native constructor
Additional Context
No response