mmerlijn/helper-time-array

TimeArray helper

v1.2 2022-02-17 22:28 UTC

This package is auto-updated.

Last update: 2024-10-12 17:32:01 UTC


README

The time array helper can handle times in array's. All times are represented as integers. Start of the day is 0 end of the day is 24*60=1440.

Example time blok

[[600,660],[720,800]]

This represent 10:00-11:00 and 12:00-13:20

If times blocks overlap each other, the blocks will be compacted to one block

Example

[[600,700],[700,800]] => [[600,800]]

Requirements

  • PHP 8.0

Installation

composer require mmerlijn/helper-time-array

Usage

#####Start 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

Or with the create method

$t = new TimeArray();
$t->create([600,700]);

#####Add times (accepts only one time interval)

$t = $t->add([600,700]); //add 10:00-11:40 

#####Substract times (accepts only one time interval)

$t = $t->substract([650,700]); //reduce the time Array

#####Get Returning the array

$t->get(); //

#####Chaning

(new TimeArray([500,600]))->add([700,800])->substract([750,800])->get();

Testing

See phpunit tests