A library for better reading of time definitions
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
composer verify
or
docker-compose up php8
docker-compose up php7