| 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: | #[\Override] |
| 26: | public function now(): \DateTimeImmutable |
| 27: | { |
| 28: | return $this->now; |
| 29: | } |
| 30: | |
| 31: | #[\Override] |
| 32: | public function sleep(float|int $seconds): void |
| 33: | { |
| 34: | $now = $this->now->format('U.u') + $seconds; |
| 35: | $now = \sprintf('@%0.6F', $now); |
| 36: | $timezone = $this->now->getTimezone(); |
| 37: | |
| 38: | $this->now = (new \DateTimeImmutable($now))->setTimezone($timezone); |
| 39: | } |
| 40: | } |
| 41: | |