bzrk/php-timeunit

A library for better reading of time definitions

0.4 2022-02-15 09:03 UTC

This package is auto-updated.

Last update: 2024-04-15 13:56:40 UTC


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