PHPackages                             ciloe/ranges - 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. ciloe/ranges

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

ciloe/ranges
============

A ranges representation library for PHP

0.0.2(1y ago)00GPL-3.0-or-laterPHPPHP ^8.2CI passing

Since Jun 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Ciloe/ranges)[ Packagist](https://packagist.org/packages/ciloe/ranges)[ RSS](/packages/ciloe-ranges/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Ranges
======

[](#ranges)

This library provides classes for working with ranges of values.

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

[](#installation)

```
composer require ciloe/ranges
```

Available Range Types
---------------------

[](#available-range-types)

### IntRange

[](#intrange)

The `IntRange` class allows you to represent and manipulate integer ranges. It offers a complete API for creating, comparing, and transforming ranges of integer numbers.

For detailed documentation on the IntRange class, see [IntRange Documentation](doc/IntRange.md).

### BigIntRange

[](#bigintrange)

The `BigIntRange` class allows you to represent and manipulate arbitrary precision integer ranges. It offers the same API as IntRange but works with string representations of integers, allowing for values beyond PHP's native integer limits (PHP\_INT\_MAX).

This class uses the BCMath extension for all operations, ensuring accurate calculations with very large integers.

For detailed documentation on the BigIntRange class, see [BigIntRange Documentation](doc/BigIntRange.md).

### DateRange

[](#daterange)

The `DateRange` class allows you to represent and manipulate date ranges. It offers a complete API for creating, comparing, and transforming ranges of dates using DateTimeImmutable objects.

This class supports custom step intervals (days, weeks, months, etc.) for generating date series and provides operations for date range manipulation.

For detailed documentation on the DateRange class, see [DateRange Documentation](doc/DateRange.md).

Quick Examples
--------------

[](#quick-examples)

### IntRange Example

[](#intrange-example)

```
use Ciloe\Ranges\IntRange;

// Create a range [1, 10]
$range = new IntRange(1, 10, '[', ']');

// Check if a value is in the range
$range->contains(5); // true

// Generate a series of values in the range
$range->generateSeries(); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
```

### BigIntRange Example

[](#bigintrange-example)

```
use Ciloe\Ranges\BigIntRange;

// Create a range with values beyond PHP_INT_MAX
// PHP_INT_MAX on 64-bit systems is 9223372036854775807
$range = new BigIntRange('9223372036854775808', '9223372036854775818', '[', ']');

// Check if a value is in the range
$range->contains('9223372036854775810'); // true

// Generate a series of values in the range
$series = $range->generateSeries(); // ['9223372036854775808', '9223372036854775809', ...]

// Perform operations with very large integers
$shifted = $range->shift('1000000000000000000');
// $shifted now represents [10223372036854775808, 10223372036854775818]

$scaled = $range->scale('2');
// $scaled now represents [18446744073709551616, 18446744073709551636]
```

### DateRange Example

[](#daterange-example)

```
use Ciloe\Ranges\DateRange;
use DateTimeImmutable;
use DateInterval;

// Create a date range from 2023-01-01 to 2023-01-10
$range = new DateRange(
    new DateTimeImmutable('2023-01-01'),
    new DateTimeImmutable('2023-01-10'),
    '[',
    ']'
);

// Check if a date is in the range
$range->contains(new DateTimeImmutable('2023-01-05')); // true

// Generate a series of dates in the range (with default 1-day step)
$dates = $range->generateSeries(); // Array of DateTimeImmutable objects from 2023-01-01 to 2023-01-10

// Create a range with weekly steps
$weeklyRange = new DateRange(
    new DateTimeImmutable('2023-01-01'),
    new DateTimeImmutable('2023-01-31'),
    '[',
    ']',
    new DateInterval('P1W')
);
$weeklyDates = $weeklyRange->generateSeries(); // [2023-01-01, 2023-01-08, 2023-01-15, 2023-01-22, 2023-01-29]

// Shift a date range
$shifted = $range->shift(new DateInterval('P1M')); // [2023-02-01, 2023-02-10]
```

Exceptions
----------

[](#exceptions)

- `InvalidArgumentException` : Invalid range format
- `InvalidBoundException` : Invalid bounds (lower &gt; upper)
- `InvalidInfiniteBoundException` : Infinite bound with inclusion
- `InvalidStepToGenerateSeriesException` : Invalid step for generating a series
- `CantGenerateSeriesBecauseTheArrayIsTooLarge` : Series too large to be generated

Notes
-----

[](#notes)

- Ranges can have infinite bounds (null)
- Bounds can be inclusive (`[`, `]`) or exclusive (`(`, `)`)
- The step only affects series generation, not other operations
- Operations between ranges (union, intersection) require the same step

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance47

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~0 days

Total

2

Last Release

394d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9dd0afe5e67dee6e70534afcabc33941729dbacdc7002458f72d509ac0979dd9?d=identicon)[Ciloe](/maintainers/Ciloe)

---

Top Contributors

[![Ciloe](https://avatars.githubusercontent.com/u/1830492?v=4)](https://github.com/Ciloe "Ciloe (6 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ciloe-ranges/health.svg)

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

###  Alternatives

[asosick/filament-layout-manager

Allow users to create &amp; customize their own FilamentPHP pages composed of Livewire components

5822.2k3](/packages/asosick-filament-layout-manager)[opengento/module-saleable

This extension allows to set if a product is saleable and can show its price by scope and customer group.

137.2k](/packages/opengento-module-saleable)

PHPackages © 2026

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