Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/symfony/clock
Decouples applications from the system clock
https://github.com/symfony/clock
clock component php psr20 symfony symfony-component time
Last synced: 4 days ago
JSON representation
Decouples applications from the system clock
- Host: GitHub
- URL: https://github.com/symfony/clock
- Owner: symfony
- License: mit
- Created: 2022-07-28T06:54:55.000Z (over 2 years ago)
- Default Branch: 7.1
- Last Pushed: 2024-11-13T15:17:12.000Z (about 1 month ago)
- Last Synced: 2024-11-28T03:02:52.074Z (25 days ago)
- Topics: clock, component, php, psr20, symfony, symfony-component, time
- Language: PHP
- Homepage: https://symfony.com/clock
- Size: 66.4 KB
- Stars: 317
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Clock Component
===============Symfony Clock decouples applications from the system clock.
Getting Started
---------------```bash
composer require symfony/clock
``````php
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
---------* [Documentation](https://symfony.com/doc/current/components/clock.html)
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)