diff --git a/CHANGELOG.md b/CHANGELOG.md index 07442d3..644249a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.11.0 + +- Added `Clock` implementation with `SystemClock` and `FixedClock`. + ## 0.10.0 - Added `is*InTimeZone(Time | Date | Month | Year $equalTo, \DateTimeZone $timeZone): bool` methods to `Moment`. diff --git a/UPGRADE.md b/UPGRADE.md index d737226..39e9d4d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade guide +## From 0.10.* to 0.11.0 + +No breaking changes. + ## From 0.9.* to 0.10.0 No breaking changes (just deprecations). @@ -38,11 +42,11 @@ When using `MomentType`, you need to migrate the database column to support mill ## From 0.6.* to 0.7.0 -No breaking changes +No breaking changes. ## From 0.5.* to 0.6.0 -No breaking changes +No breaking changes. ## From 0.4.* to 0.5.0 @@ -50,7 +54,7 @@ You can remove `YearNormalizer` from your normalizers if you registered it manua ## From 0.3.* to 0.4.0 -No breaking changes +No breaking changes. ## From 0.2.* to 0.3.0 @@ -85,4 +89,4 @@ if ($date->day === 15) { ## From 0.1.* to 0.2.0 -No breaking changes +No breaking changes. diff --git a/docker-compose.yml b/docker-compose.yml index 1296c87..215afe8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.7' - services: php-8.2: diff --git a/src/Clock/Clock.php b/src/Clock/Clock.php new file mode 100644 index 0000000..9d2bfd3 --- /dev/null +++ b/src/Clock/Clock.php @@ -0,0 +1,12 @@ +moment = $moment ?? Moment::fromDateTime(new \DateTimeImmutable('now')); + } + + public function freeze(Moment $moment): void + { + $this->moment = $moment; + } + + #[\Override] + public function now(): Moment + { + return $this->moment; + } +} diff --git a/src/Clock/SystemClock.php b/src/Clock/SystemClock.php new file mode 100644 index 0000000..4c23117 --- /dev/null +++ b/src/Clock/SystemClock.php @@ -0,0 +1,19 @@ +now()); + } + + #[Test] + public function freeze_works(): void + { + // -- Arrange + $clock = new FrozenClock(); + $moment = Moment::fromStringInTimeZone('2024-05-06 08:00:00', new \DateTimeZone('Europe/Berlin')); + + // -- Act + $clock->freeze($moment); + + // -- Assert + self::assertSame($moment, $clock->now()); + } +} diff --git a/tests/Clock/SystemClockTest.php b/tests/Clock/SystemClockTest.php new file mode 100644 index 0000000..e78f271 --- /dev/null +++ b/tests/Clock/SystemClockTest.php @@ -0,0 +1,29 @@ +now(); + + // -- Assert + self::assertEquals($moment->dateTime->getTimezone(), new \DateTimeZone('UTC')); + } +}