Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ergebnis/clock
⏰ Provides a composer package with abstractions of a clock.
https://github.com/ergebnis/clock
clock system-clock test-clock
Last synced: 3 days ago
JSON representation
⏰ Provides a composer package with abstractions of a clock.
- Host: GitHub
- URL: https://github.com/ergebnis/clock
- Owner: ergebnis
- License: mit
- Created: 2018-01-30T22:21:32.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-27T18:31:06.000Z (7 months ago)
- Last Synced: 2024-05-28T04:07:33.557Z (7 months ago)
- Topics: clock, system-clock, test-clock
- Language: PHP
- Size: 3.05 MB
- Stars: 30
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# clock
[![Integrate](https://github.com/ergebnis/clock/workflows/Integrate/badge.svg)](https://github.com/ergebnis/clock/actions)
[![Merge](https://github.com/ergebnis/clock/workflows/Merge/badge.svg)](https://github.com/ergebnis/clock/actions)
[![Release](https://github.com/ergebnis/clock/workflows/Release/badge.svg)](https://github.com/ergebnis/clock/actions)
[![Renew](https://github.com/ergebnis/clock/workflows/Renew/badge.svg)](https://github.com/ergebnis/clock/actions)[![Code Coverage](https://codecov.io/gh/ergebnis/clock/branch/main/graph/badge.svg)](https://codecov.io/gh/ergebnis/clock)
[![Latest Stable Version](https://poser.pugx.org/ergebnis/clock/v/stable)](https://packagist.org/packages/ergebnis/clock)
[![Total Downloads](https://poser.pugx.org/ergebnis/clock/downloads)](https://packagist.org/packages/ergebnis/clock)
[![Monthly Downloads](http://poser.pugx.org/ergebnis/clock/d/monthly)](https://packagist.org/packages/ergebnis/clock)This project provides a [`composer`](https://getcomposer.org) package with abstractions of a clock, following the suggestion by [Martin Fowler](https://martinfowler.com/bliki/ClockWrapper.html), and compatible with [PSR-20](https://www.php-fig.org/psr/psr-20/).
## Installation
Run
```sh
composer require ergebnis/clock
```## Usage
### `SystemClock`
Create a new `SystemClock` and use it to determine the current time in a specific time zone:
```php
now();
```Freeze a `SystemClock` to turn it into a `FrozenClock`:
```php
freeze();$now = $clock->now();
sleep(5);
$stillNow = $clock->now();
```### `UtcClock`
Create a new `UtcClock` and use it to determine the current time in the UTC time zone:
```php
now();
```Freeze a `UtcClock` to turn it into a `FrozenClock`:
```php
freeze();$now = $clock->now();
sleep(5);
$stillNow = $clock->now();
```### `FrozenClock`
Create a new frozen clock and use it in tests:
```php
now();
```## Changelog
The maintainers of this project record notable changes to this project in a [changelog](CHANGELOG.md).
## Contributing
The maintainers of this project suggest following the [contribution guide](.github/CONTRIBUTING.md).
## Code of Conduct
The maintainers of this project ask contributors to follow the [code of conduct](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).
## General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by [sponsoring @localheinz](https://github.com/sponsors/localheinz) or [requesting an invoice for services related to this project](mailto:[email protected]?subject=ergebnis/clock:%20Requesting%20invoice%20for%20services).
## PHP Version Support Policy
This project supports PHP versions with [active and security support](https://www.php.net/supported-versions.php).
The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.
## Security Policy
This project has a [security policy](.github/SECURITY.md).
## License
This project uses the [MIT license](LICENSE.md).
## Credits
This project is inspired by [`lcobucci/clock`](https://github.com/lcobucci/clock) (originally licensed under MIT by [Luís Cobucci](https://github.com/lcobucci)).
## Social
Follow [@localheinz](https://twitter.com/intent/follow?screen_name=localheinz) and [@ergebnis](https://twitter.com/intent/follow?screen_name=ergebnis) on Twitter.