ikarusbot/vendor/symfony/clock
2025-01-10 19:52:34 +02:00
..
Resources first commit 2025-01-10 19:52:34 +02:00
Test first commit 2025-01-10 19:52:34 +02:00
CHANGELOG.md first commit 2025-01-10 19:52:34 +02:00
Clock.php first commit 2025-01-10 19:52:34 +02:00
ClockAwareTrait.php first commit 2025-01-10 19:52:34 +02:00
ClockInterface.php first commit 2025-01-10 19:52:34 +02:00
composer.json first commit 2025-01-10 19:52:34 +02:00
DatePoint.php first commit 2025-01-10 19:52:34 +02:00
LICENSE first commit 2025-01-10 19:52:34 +02:00
MockClock.php first commit 2025-01-10 19:52:34 +02:00
MonotonicClock.php first commit 2025-01-10 19:52:34 +02:00
NativeClock.php first commit 2025-01-10 19:52:34 +02:00
README.md first commit 2025-01-10 19:52:34 +02:00

Clock Component

Symfony Clock decouples applications from the system clock.

Getting Started

composer require symfony/clock
use Symfony\Component\Clock\NativeClock;
use Symfony\Component\Clock\ClockInterface;

class MyClockSensitiveClass
{
    public function __construct(
        private ClockInterface $clock,
    ) {
        // Only if you need to force a timezone:
        //$this->clock = $clock->withTimeZone('UTC');
    }

    public function doSomething()
    {
        $now = $this->clock->now();
        // [...] do something with $now, which is a \DateTimeImmutable object

        $this->clock->sleep(2.5); // Pause execution for 2.5 seconds
    }
}

$clock = new NativeClock();
$service = new MyClockSensitiveClass($clock);
$service->doSomething();

Resources