symfony / clock
Decouples applications from the system clock
Fund package maintenance!
fabpot
Tidelift
symfony.com/sponsor
Requires
- php: >=8.2
- psr/clock: ^1.0
- symfony/polyfill-php83: ^1.28
Provides
- 7.2.x-dev
- v7.2.0-BETA1
- 7.1.x-dev
- v7.1.6
- v7.1.1
- v7.1.0
- v7.1.0-RC1
- v7.1.0-BETA1
- 7.0.x-dev
- v7.0.8
- v7.0.7
- v7.0.5
- v7.0.3
- v7.0.2
- v7.0.0
- v7.0.0-RC2
- v7.0.0-RC1
- v7.0.0-BETA1
- 6.4.x-dev
- v6.4.13
- v6.4.8
- v6.4.7
- v6.4.5
- v6.4.3
- v6.4.2
- v6.4.0
- v6.4.0-RC1
- v6.4.0-BETA1
- 6.3.x-dev
- v6.3.12
- v6.3.11
- v6.3.4
- v6.3.1
- v6.3.0
- v6.3.0-RC1
- v6.3.0-BETA1
- 6.2.x-dev
- v6.2.12
- v6.2.7
- v6.2.5
- v6.2.2
- v6.2.0
- v6.2.0-RC2
- v6.2.0-RC1
- v6.2.0-BETA3
- v6.2.0-BETA1
This package is auto-updated.
Last update: 2024-10-27 15:25:19 UTC
README
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();