-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSystemClock.php
More file actions
35 lines (28 loc) · 709 Bytes
/
SystemClock.php
File metadata and controls
35 lines (28 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
declare(strict_types=1);
namespace SonsOfPHP\Component\Clock;
use DateTimeImmutable;
use DateTimeZone;
use Psr\Clock\ClockInterface;
use Stringable;
/**
* System Clock.
*
* @author Joshua Estes <joshua@sonsofphp.com>
*/
class SystemClock implements ClockInterface, Stringable
{
public function __construct(private readonly DateTimeZone $zone = new DateTimeZone('UTC')) {}
public function __toString(): string
{
return 'SystemClock[' . $this->zone->getName() . ']';
}
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('now', $this->zone);
}
public function getZone(): DateTimeZone
{
return $this->zone;
}
}