Skip to content

supertanuki/TimeOverlap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TimeOverlap

Time overlap utilities

Overlap

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

Touch

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

Create a period of time

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

About

Time overlap PHP utilities

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages