2020 */
2121final class MockClockimplements ClockInterface
2222{
23- private \ DateTimeImmutable $ now ;
23+ private TimePoint $ now ;
2424
2525/**
2626 * @throws \DateMalformedStringException When $now is invalid
@@ -38,20 +38,16 @@ public function __construct(\DateTimeImmutable|string $now = 'now', \DateTimeZon
3838 }
3939 }
4040
41- if (\PHP_VERSION_ID >=80300 &&\is_string ($ now )) {
42- $ now =new \DateTimeImmutable ($ now ,$ timezone ??new \DateTimeZone ('UTC ' ));
43- }elseif (\is_string ($ now )) {
44- try {
45- $ now =new \DateTimeImmutable ($ now ,$ timezone ??new \DateTimeZone ('UTC ' ));
46- }catch (\Exception $ e ) {
47- throw new \DateMalformedStringException ($ e ->getMessage (),$ e ->getCode (),$ e );
48- }
41+ if (\is_string ($ now )) {
42+ $ now =new TimePoint ($ now ,$ timezone ??new \DateTimeZone ('UTC ' ));
43+ }elseif (!$ nowinstanceof TimePoint) {
44+ $ now = TimePoint::createFromInterface ($ now );
4945 }
5046
5147$ this ->now =null !==$ timezone ?$ now ->setTimezone ($ timezone ) :$ now ;
5248 }
5349
54- public function now ():\ DateTimeImmutable
50+ public function now ():TimePoint
5551 {
5652return clone $ this ->now ;
5753 }
@@ -62,7 +58,7 @@ public function sleep(float|int $seconds): void
6258$ now =substr_replace (sprintf ('@%07.0F ' ,$ now ),'. ' , -6 ,0 );
6359$ timezone =$ this ->now ->getTimezone ();
6460
65- $ this ->now = (new \DateTimeImmutable ($ now ,$ timezone ))->setTimezone ($ timezone );
61+ $ this ->now =TimePoint:: createFromInterface (new \DateTimeImmutable ($ now ,$ timezone ))->setTimezone ($ timezone );
6662 }
6763
6864/**