1: <?php
2:
3: declare(strict_types=1);
4:
5: /**
6: * This file is part of the Nexus framework.
7: *
8: * (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9: *
10: * For the full copyright and license information, please view
11: * the LICENSE file that was distributed with this source code.
12: */
13:
14: namespace Nexus\Clock;
15:
16: /**
17: * A clock that always shows the same time.
18: */
19: final class FrozenClock implements Clock
20: {
21: public function __construct(private \DateTimeImmutable $now) {}
22:
23: #[\Override]
24: public function now(): \DateTimeImmutable
25: {
26: return $this->now;
27: }
28:
29: #[\Override]
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: