Time overlap utilities
To test that two periods of time overlap:
[ one ]
[ another ]
or
[ one ]
[ another ]
or
[ one ]
[ another ]
or
[ one ]
[ another ]
or
[ one ]
[ another ]
or
[one]
[ another ]
use Supertanuki\TimeOverlap\TimeOverlap;
use Supertanuki\TimeOverlap\TimeRangeView;
TimeOverlap::overlap(
new TimeRangeView(new \DateTime('2018-10-29 09:00:00'), new \DateTime('2018-10-29 10:00:00')),
new TimeRangeView(new \DateTime('2018-10-29 09:30:00'), new \DateTime('2018-10-29 11:00:00'))
);
// will return true
TimeOverlap::overlap(
new TimeRangeView(new \DateTime('2018-10-29 09:00:00'), new \DateTime('2018-10-29 11:00:00')),
new TimeRangeView(new \DateTime('2018-10-29 10:00:00'), new \DateTime('2018-10-29 10:35:00'))
);
// will return true
TimeOverlap::overlap(
new TimeRangeView(new \DateTime('2018-10-29 10:00:00'), new \DateTime('2018-10-29 11:00:00')),
new TimeRangeView(new \DateTime('2018-10-29 11:05:00'), new \DateTime('2018-10-29 12:00:00'))
);
// will return false
To test that two periods of time are contiguous:
[one]
[another]
or
[another]
[one]
use Supertanuki\TimeOverlap\TimeOverlap;
use Supertanuki\TimeOverlap\TimeRangeView;
TimeOverlap::touch(
new TimeRangeView(new \DateTime('2018-10-29 09:00:00'), new \DateTime('2018-10-29 10:00:00')),
new TimeRangeView(new \DateTime('2018-10-29 10:00:00'), new \DateTime('2018-10-29 11:00:00'))
);
// will return true
TimeOverlap::touch(
new TimeRangeView(new \DateTime('2018-10-29 10:00:00'), new \DateTime('2018-10-29 11:00:00')),
new TimeRangeView(new \DateTime('2018-10-29 09:00:00'), new \DateTime('2018-10-29 10:00:00'))
);
// will return true
TimeOverlap::touch(
new TimeRangeView(new \DateTime('2018-10-29 10:00:00'), new \DateTime('2018-10-29 11:00:00')),
new TimeRangeView(new \DateTime('2018-10-29 11:05:00'), new \DateTime('2018-10-29 12:00:00'))
);
// will return false
Use TimeRangeView:
use Supertanuki\TimeOverlap\TimeRangeView;
new TimeRangeView(new \DateTime('2018-10-29 09:00:00'), new \DateTime('2018-10-29 10:00:00'));
or create your own class implementing Supertanuki\TimeOverlap\TimeRangeInterface