33 lines
595 B
PHP
33 lines
595 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Lcobucci\Clock;
|
|
|
|
use DateTimeImmutable;
|
|
use DateTimeZone;
|
|
|
|
final class FrozenClock implements Clock
|
|
{
|
|
private DateTimeImmutable $now;
|
|
|
|
public function __construct(DateTimeImmutable $now)
|
|
{
|
|
$this->now = $now;
|
|
}
|
|
|
|
public static function fromUTC(): self
|
|
{
|
|
return new self(new DateTimeImmutable('now', new DateTimeZone('UTC')));
|
|
}
|
|
|
|
public function setTo(DateTimeImmutable $now): void
|
|
{
|
|
$this->now = $now;
|
|
}
|
|
|
|
public function now(): DateTimeImmutable
|
|
{
|
|
return $this->now;
|
|
}
|
|
}
|