bzrk / php-timeunit
A library for better reading of time definitions
0.4
2022-02-15 09:03 UTC
Requires
- php: >= 7.4
Requires (Dev)
- phpstan/phpstan: >=0.12.99
- phpunit/phpunit: >=9.5.0
- squizlabs/php_codesniffer: 3.*
README
A library for better reading of time definitions
Examples
better readable code
Plain PHP
sleep(60*60*3); // 3 Hours sleep(60*45); // 45 Minutes $time = \time(); - (60*60*3);
PHP Timeunit
TimeUnit::ofHours(3)->sleep(); TimeUnit::ofMinutes(45)->sleep(); TimeUnit::now()->minus(TimeUnit::ofMinutes(3));
Type usage
Plain PHP
function a(int $seconds) { //whatever doing with the seconds } a(-123455); a(1234);
PHP Timeunit
function a(TimeUnit $time) { //whatever doing with the seconds } a(TimeUnit::ofSeconds(12)); a(TimeUnit::ofSeconds(-12)); throws a InvalidArgumentException
Running tests
composer verify
or
docker-compose up php8 docker-compose up php7