https://github.com/php-fig/clock
PSR-20 repository
https://github.com/php-fig/clock
clock php psr-20
Last synced: 8 months ago
JSON representation
PSR-20 repository
- Host: GitHub
- URL: https://github.com/php-fig/clock
- Owner: php-fig
- License: mit
- Created: 2021-07-14T21:21:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-21T14:30:19.000Z (over 2 years ago)
- Last Synced: 2025-06-05T02:39:18.092Z (8 months ago)
- Topics: clock, php, psr-20
- Language: PHP
- Homepage: https://www.php-fig.org/psr/psr-20/
- Size: 23.4 KB
- Stars: 561
- Watchers: 11
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PSR Clock
This repository holds the interface for [PSR-20][psr-url].
Note that this is not a clock of its own. It is merely an interface that
describes a clock. See the specification for more details.
## Installation
```bash
composer require psr/clock
```
## Usage
If you need a clock, you can use the interface like this:
```php
clock = $clock;
}
public function doSomething()
{
/** @var DateTimeImmutable $currentDateAndTime */
$currentDateAndTime = $this->clock->now();
// do something useful with that information
}
}
```
You can then pick one of the [implementations][implementation-url] of the interface to get a clock.
If you want to implement the interface, you can require this package and
implement `Psr\Clock\ClockInterface` in your code.
Don't forget to add `psr/clock-implementation` to your `composer.json`s `provide`-section like this:
```json
{
"provide": {
"psr/clock-implementation": "1.0"
}
}
```
And please read the [specification text][specification-url] for details on the interface.
[psr-url]: https://www.php-fig.org/psr/psr-20
[package-url]: https://packagist.org/packages/psr/clock
[implementation-url]: https://packagist.org/providers/psr/clock-implementation
[specification-url]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-20-clock.md