bzrk/php-timeunit

用于更好地读取时间定义的库

0.4 2022-02-15 09:03 UTC

This package is auto-updated.

Last update: 2024-09-15 14:49:02 UTC


README

用于更好地读取时间定义的库

示例

更易于阅读的代码

纯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));

类型使用

纯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

或者

docker-compose up php8
docker-compose up php7