1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | namespace Nexus\Clock; |
15: | |
16: | |
17: | |
18: | |
19: | final class FrozenClock implements Clock |
20: | { |
21: | public function __construct( |
22: | private \DateTimeImmutable $now, |
23: | ) {} |
24: | |
25: | public function now(): \DateTimeImmutable |
26: | { |
27: | return $this->now; |
28: | } |
29: | |
30: | public function sleep(float|int $seconds): void |
31: | { |
32: | $now = $this->now->format('U.u') + $seconds; |
33: | $now = \sprintf('@%0.6F', $now); |
34: | $timezone = $this->now->getTimezone(); |
35: | |
36: | $this->now = (new \DateTimeImmutable($now))->setTimezone($timezone); |
37: | } |
38: | } |
39: | |