mmerlijn / helper-time-array
TimeArray 辅助工具
v1.2
2022-02-17 22:28 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: 9.5.x-dev
This package is auto-updated.
Last update: 2024-09-12 17:20:47 UTC
README
时间数组辅助工具可以处理数组中的时间。所有时间都表示为整数。一天的开始是 0,结束是 24*60=1440。
示例时间块
[[600,660],[720,800]]
这代表 10:00-11:00 和 12:00-13:20
如果时间块重叠,则块将被压缩成一个块
示例
[[600,700],[700,800]] => [[600,800]]
要求
- PHP 8.0
安装
composer require mmerlijn/helper-time-array
使用
##### 开始时间数组
$t = new TimeArray(); //or with initial value $t = new TimeArray([[500,600],[700,800]]); //multiple intervals $t = new TimeArray([600,720]); //one interval
或者使用 create 方法
$t = new TimeArray(); $t->create([600,700]);
##### 添加时间(仅接受一个时间区间)
$t = $t->add([600,700]); //add 10:00-11:40
##### 减去时间(仅接受一个时间区间)
$t = $t->substract([650,700]); //reduce the time Array
##### 返回数组
$t->get(); //
##### 修改
(new TimeArray([500,600]))->add([700,800])->substract([750,800])->get();
测试
查看 phpunit 测试