Downloads this Month Latest Stable Version Build Status

  • Code Climate
  • Coverage Status
  • SensioLabsInsight: SensioLabsInsight
  • Dependency Status

Note: I use this projects for testing many cloud services. That's why you see so many badges here. :)


composer require achse/php-math-interval


Creating an interval

Via factories (most simple, most encapsulated):

$interval = DateTimeIntervalFactory::create('2015-10-07 12:00:00', Boundary::CLOSED, '2015-10-07 14:00:00', Boundary::OPENED);

Directly via constructors:

use Achse\Math\Interval\Types\DateTime; # We need one that implements IComparable

$left = new IntegerBoundary(new DateTime('2015-10-07 12:00:00'), Boundary::CLOSED);
$right = new IntegerBoundary(new DateTime('2015-10-07 14:00:00'), Boundary::OPENED);
$interval = new DateTimeInterval($left, $right);

Parsed from string (used for tests mostly):

$interval = DateTimeIntervalStringParser::parse('[2015-01-01 05:00:00, 2015-01-01 10:00:00)');


Interval have all basic operations like:

  • isContainingElement,
  • getIntersection,
  • getDifference,
  • and many others.

Available Types

Library contains intervals for those types:

  • Integer - classic int,
  • DateTime - classic DateTime from Nette\Utils but implements IComparable,
  • SingeDayTime - represents "clock-time" from 00:00:00 to 23:59:59.

Other types: Interval (its Boundary) can contains any type that implements IComparable, but if you want to have type-hinting you have to write your own XyInterval and XyBoundary class and probably also Factory classes.

Motivation, main purpose

This library was created for working properly with opening hours of restaurants. If you miss some type or method od simply just some feature, don't hesitate to send pull request. I'll be really happy. :)

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette