20
20
*/
21
21
final class MockClock implements ClockInterface
22
22
{
23
- private \ DateTimeImmutable $ now ;
23
+ private TimePoint $ now ;
24
24
25
25
/**
26
26
* @throws \DateMalformedStringException When $now is invalid
@@ -38,20 +38,16 @@ public function __construct(\DateTimeImmutable|string $now = 'now', \DateTimeZon
38
38
}
39
39
}
40
40
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 (!$ now instanceof TimePoint) {
44
+ $ now = TimePoint::createFromInterface ($ now );
49
45
}
50
46
51
47
$ this ->now = null !== $ timezone ? $ now ->setTimezone ($ timezone ) : $ now ;
52
48
}
53
49
54
- public function now (): \ DateTimeImmutable
50
+ public function now (): TimePoint
55
51
{
56
52
return clone $ this ->now ;
57
53
}
@@ -62,7 +58,7 @@ public function sleep(float|int $seconds): void
62
58
$ now = substr_replace (sprintf ('@%07.0F ' , $ now ), '. ' , -6 , 0 );
63
59
$ timezone = $ this ->now ->getTimezone ();
64
60
65
- $ this ->now = (new \DateTimeImmutable ($ now , $ timezone ))->setTimezone ($ timezone );
61
+ $ this ->now = TimePoint:: createFromInterface (new \DateTimeImmutable ($ now , $ timezone ))->setTimezone ($ timezone );
66
62
}
67
63
68
64
/**
0 commit comments