PHPackages                             puovils/intervals - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. puovils/intervals

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

puovils/intervals
=================

Manipulation with intervals

v1.0.0(12y ago)5241MITPHPPHP &gt;=5.4.0

Since Sep 25Pushed 12y ago1 watchersCompare

[ Source](https://github.com/povilas/intervals)[ Packagist](https://packagist.org/packages/puovils/intervals)[ RSS](/packages/puovils-intervals/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (2)Used By (0)

README
======

[](#readme)

[![Build Status](https://camo.githubusercontent.com/b9c3a6ffc99930c29c776408125b1c0988e93a5a7fd8ede3769695c90a98c05d/68747470733a2f2f7472617669732d63692e6f72672f706f76696c61732f696e74657276616c732e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/povilas/intervals)

What is this?
-------------

[](#what-is-this)

This libary helps you to work with intervals. Currently supported operations:

```
Addition example:
[1, 2] + [2, 3]          = [1, 3]
[1, 3) + (3, 5]          = [1, 3); (3, 5]
(1, 3) + (3, 5] + [1, 4) = [1, 5]

Subtraction example:
[1, 4] - [2, 3] = [1, 2); (3, 4]
[1, 4] - (2, 5] = [1, 2]

```

Intervals can contain any type of data. Integers, string, arrays, \\DateTime, etc. You just need to provide function witch can perform comaprision of your data type.

Installation
------------

[](#installation)

```
composer.phar require "puovils/intervals=1.0.*@dev"
```

Usage
-----

[](#usage)

Simple example with integers

```
$builder = new IntervalBuilder();

$interval1 = $builder
    ->low(1, true)   // [1
    ->high(5, false) // 5)
    ->getInterval(); // [1, 5)

$interval2 = $builder
    ->low(2, false)  // (2
    ->high(3, true)  // 3]
    ->getInterval(); // (2, 3]

$intervalCollection= new IntervalCollection();
$intervals = $intervalCollection
    ->add($interval1) // [1, 5)
    ->sub($interval2) // (2, 3]
    ->getIntervals(); // [1, 2]; (3, 5)

echo $intervals[0]->low()->value();       // 1
echo $intervals[0]->low()->isIncluded();  // true
echo $intervals[0]->high()->value();      // 2
echo $intervals[0]->high()->isIncluded(); // true

echo $intervals[1]->low()->value();       // 3
echo $intervals[1]->low()->isIncluded();  // false
echo $intervals[1]->high()->value();      // 5
echo $intervals[1]->high()->isIncluded(); // false
```

With `\DateTime`

```
$builder = new IntervalBuilder();

$interval1 = $builder
    ->low(new \DateTime('2000-01-15'), true)
    ->high(new \DateTime('2000-02-15'), true)
    ->getInterval();

$interval2 = $builder
    ->low(new \DateTime('2000-01-17'), true)
    ->high(new \DateTime('2000-03-01'), false)
    ->getInterval();

$intervalCollection= new IntervalCollection(
    function (\DateTime $a, \DateTime $b) {
        if ($a->getTimestamp() == $b->getTimestamp()) {
            return 0;
        }
        return $a->getTimestamp() > $b->getTimestamp() ? 1 : -1;
    }
);
$intervals = $intervalCollection
    ->add($interval1)
    ->add($interval2)
    ->getIntervals();

echo $intervals[0]->low()->value()->format('Y-m-d'); // 2000-01-15
echo $intervals[0]->low()->isIncluded(); // true
echo $intervals[0]->high()->value()->format('Y-m-d'); // 2000-03-01
echo $intervals[0]->high()->isIncluded(); // false
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4662d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/149357?v=4)[Povilas Skruibis](/maintainers/povilas)[@povilas](https://github.com/povilas)

---

Top Contributors

[![povilas](https://avatars.githubusercontent.com/u/149357?v=4)](https://github.com/povilas "povilas (5 commits)")[![drrcknlsn](https://avatars.githubusercontent.com/u/2717358?v=4)](https://github.com/drrcknlsn "drrcknlsn (1 commits)")

---

Tags

datetimetimedateintervaldateinterval

### Embed Badge

![Health badge](/badges/puovils-intervals/health.svg)

```
[![Health](https://phpackages.com/badges/puovils-intervals/health.svg)](https://phpackages.com/packages/puovils-intervals)
```

###  Alternatives

[league/period

Time range API for PHP

7335.7M22](/packages/league-period)[brick/date-time

Date and time library

3623.6M94](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

20410.2M16](/packages/aeon-php-calendar)[tplaner/when

Date/Calendar recursion library.

5261.1M7](/packages/tplaner-when)[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.6M3](/packages/kartik-v-php-date-formatter)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14283.6k](/packages/dater-dater)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
