File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 77use DateTimeImmutable ;
88use DateTimeZone ;
99
10+ use function date_default_timezone_get ;
11+
1012final class FrozenClock implements Clock
1113{
1214 public function __construct (private DateTimeImmutable $ now )
@@ -18,6 +20,11 @@ public static function fromUTC(): self
1820 return new self (new DateTimeImmutable ('now ' , new DateTimeZone ('UTC ' )));
1921 }
2022
23+ public static function fromSystemTimezone (): self
24+ {
25+ return new self (new DateTimeImmutable ('now ' , new DateTimeZone (date_default_timezone_get ())));
26+ }
27+
2128 public function setTo (DateTimeImmutable $ now ): void
2229 {
2330 $ this ->now = $ now ;
Original file line number Diff line number Diff line change 99use PHPUnit \Framework \Attributes \Test ;
1010use PHPUnit \Framework \TestCase ;
1111
12+ use function date_default_timezone_get ;
13+
1214#[CoversClass(FrozenClock::class)]
1315final class FrozenClockTest extends TestCase
1416{
@@ -71,4 +73,13 @@ public function fromUTCCreatesClockFrozenAtCurrentSystemTimeInUTC(): void
7173
7274 self ::assertSame ('UTC ' , $ now ->getTimezone ()->getName ());
7375 }
76+
77+ #[Test]
78+ public function fromSystemTimezoneCreatesAnInstanceUsingTheDefaultTimezoneInSystem (): void
79+ {
80+ $ clock = FrozenClock::fromSystemTimezone ();
81+ $ now = $ clock ->now ();
82+
83+ self ::assertSame (date_default_timezone_get (), $ now ->getTimezone ()->getName ());
84+ }
7485}
You can’t perform that action at this time.
0 commit comments