├── LICENSE ├── composer.json └── src ├── Clock.php ├── FrozenClock.php └── SystemClock.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Luís Cobucci 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 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lcobucci/clock", 3 | "description": "Yet another clock abstraction", 4 | "license": "MIT", 5 | "type": "library", 6 | "authors": [ 7 | { 8 | "name": "Luís Cobucci", 9 | "email": "lcobucci@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": "~8.3.0 || ~8.4.0", 14 | "psr/clock": "^1.0" 15 | }, 16 | "require-dev": { 17 | "infection/infection": "^0.29", 18 | "lcobucci/coding-standard": "^11.1.0", 19 | "phpstan/extension-installer": "^1.3.1", 20 | "phpstan/phpstan": "^2.0.0", 21 | "phpstan/phpstan-deprecation-rules": "^2.0.0", 22 | "phpstan/phpstan-phpunit": "^2.0.0", 23 | "phpstan/phpstan-strict-rules": "^2.0.0", 24 | "phpunit/phpunit": "^12.0.0" 25 | }, 26 | "provide": { 27 | "psr/clock-implementation": "1.0" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Lcobucci\\Clock\\": "src" 32 | } 33 | }, 34 | "autoload-dev": { 35 | "psr-4": { 36 | "Lcobucci\\Clock\\": "test" 37 | } 38 | }, 39 | "config": { 40 | "allow-plugins": { 41 | "dealerdirect/phpcodesniffer-composer-installer": true, 42 | "infection/extension-installer": true, 43 | "phpstan/extension-installer": true 44 | }, 45 | "preferred-install": "dist", 46 | "sort-packages": true 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Clock.php: -------------------------------------------------------------------------------- 1 | now = $now; 24 | } 25 | 26 | /** 27 | * Adjusts the current time by a given modifier. 28 | * 29 | * @param string $modifier @see https://www.php.net/manual/en/datetime.formats.php 30 | * 31 | * @throws DateMalformedStringException When an invalid date/time string is passed. 32 | */ 33 | public function adjustTime(string $modifier): void 34 | { 35 | $this->now = $this->now->modify($modifier); 36 | } 37 | 38 | public function now(): DateTimeImmutable 39 | { 40 | return $this->now; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/SystemClock.php: -------------------------------------------------------------------------------- 1 | timezone); 31 | } 32 | } 33 | --------------------------------------------------------------------------------