├── CHANGELOG.md ├── LICENSE ├── README.md ├── SECURITY.md ├── composer.json └── src ├── Clock.php └── Clock ├── FrozenClock.php └── SystemClock.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## 1.2 - 2022-04-20 4 | 5 | This release introduces a compatibility layer with the PSR-20 draft, allowing us to already 6 | get some interoperability by depending on a shared interface. 7 | 8 | ## 1.1 - 2020-10-04 9 | 10 | * The default branch of the GitHub repository has been renamed from `master` to `main` - 11 | if you're using `dev-master` as a version constraint in your `composer.json`, please 12 | update it to `dev-main`. 13 | * Added PHP 8 forward compatibility 14 | 15 | ## 1.0.1 - 2019-08-26 16 | 17 | - Remove `phpunit/phpunit` from non-dev dependencies. 18 | 19 | ## 1.0.0 - 2019-08-20 20 | 21 | Initial release 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Jérôme Gamez, https://github.com/jeromegamez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clock 2 | 3 | A PHP 7.0 compatible clock abstraction. 4 | 5 | [![Current version](https://img.shields.io/packagist/v/kreait/clock.svg)](https://packagist.org/packages/kreait/clock) 6 | [![Supported PHP version](https://img.shields.io/packagist/php-v/kreait/clock.svg)]() 7 | [![Monthly Downloads](https://img.shields.io/packagist/dm/kreait/clock.svg)](https://packagist.org/packages/kreait/clock/stats) 8 | [![Total Downloads](https://img.shields.io/packagist/dt/kreait/clock.svg)](https://packagist.org/packages/kreait/clock/stats) 9 | [![Tests](https://github.com/kreait/clock-php/actions/workflows/tests.yml/badge.svg)](https://github.com/kreait/clock-php/actions/workflows/tests.yml) 10 | [![Discord](https://img.shields.io/discord/807679292573220925.svg?color=7289da&logo=discord)](https://discord.gg/Yacm7unBsr) 11 | 12 | ## Installation 13 | 14 | ```bash 15 | composer require kreait/clock 16 | ``` 17 | 18 | ## Basic usage 19 | 20 | ```php 21 | now()); 30 | 31 | $frozenClock = new FrozenClock(new DateTimeImmutable('2019-08-20 10:41:53')); 32 | var_dump($frozenClock->now()); 33 | 34 | $frozenClock->setTo(new DateTimeImmutable('2019-08-19 19:19:19')); 35 | var_dump($frozenClock->now()); 36 | ``` 37 | 38 | ## Credits 39 | 40 | This project exists because [lcobucci/clock](https://github.com/lcobucci/clock) (rightfully) 41 | doesn't support PHP 7.0 anymore, but we need a clock in [kreait/firebase-php 4.x](https://github.com/kreait/firebase-php) 42 | and [kreait/firebase-tokens 1.x](https://github.com/kreait/firebase-tokens-php) for backwards compatibility. 43 | 44 | ## License 45 | 46 | The MIT License (MIT). Please see [License File](LICENSE) for more information. 47 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Security contact information 2 | 3 | To report a security vulnerability, please use the 4 | [Tidelift security contact](https://tidelift.com/security). 5 | Tidelift will coordinate the fix and disclosure. 6 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kreait/clock", 3 | "description": "A PHP 7.0 compatible clock abstraction", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Jérôme Gamez", 9 | "email": "jerome@gamez.name" 10 | } 11 | ], 12 | "require": { 13 | "php": "^7.0|^8.0", 14 | "stella-maris/clock": "^0.1.4" 15 | }, 16 | "autoload": { 17 | "psr-4": { 18 | "Kreait\\Clock\\": "src/Clock" 19 | }, 20 | "files": [ 21 | "src/Clock.php" 22 | ] 23 | }, 24 | "require-dev": { 25 | "phpunit/phpunit": "^6.5.14" 26 | }, 27 | "autoload-dev": { 28 | "psr-4": { 29 | "Kreait\\Tests\\Clock\\": "tests" 30 | } 31 | }, 32 | "config": { 33 | "sort-packages": true, 34 | "platform": { 35 | "php": "7.0.33" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Clock.php: -------------------------------------------------------------------------------- 1 | now = $now; 18 | } 19 | 20 | public function setTo(DateTimeImmutable $now) 21 | { 22 | $this->now = $now; 23 | } 24 | 25 | public function now(): DateTimeImmutable 26 | { 27 | return $this->now; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Clock/SystemClock.php: -------------------------------------------------------------------------------- 1 | timezone = $timezone ?: new DateTimeZone(date_default_timezone_get()); 20 | } 21 | 22 | public function now(): DateTimeImmutable 23 | { 24 | return new DateTimeImmutable('now', $this->timezone); 25 | } 26 | } 27 | --------------------------------------------------------------------------------