Download the PHP package ciloe/ranges without Composer
On this page you can find all versions of the php package ciloe/ranges. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package ranges
Short Description A ranges representation library for PHP
License GPL-3.0-or-later
Informations about the package ranges
Ranges
This library provides classes for working with ranges of values.
Requirements
- PHP 8.3 or higher
- The BCMath extension (
ext-bcmath), used byBigIntRange
Installation
Available Range Types
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.
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.
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.
TimeRange
The TimeRange class allows you to represent and manipulate time-of-day ranges. All comparisons only use the time part (hours, minutes, seconds) of the DateTimeImmutable objects — the date part is ignored.
This class supports custom step intervals (seconds, minutes, hours) for generating time series and provides the same operations as the other range types.
For detailed documentation on the TimeRange class, see TimeRange Documentation.
RangeCollection
The RangeCollection class is an immutable collection of ranges of the same type and step. It normalizes overlapping ranges (merge()), finds the free slots between them (gaps()), and sums their lengths (totalLength()).
For detailed documentation on the RangeCollection class, see RangeCollection Documentation.
Available Operations
Every range type implements the same API:
- Predicates :
contains(),containsRange(),overlap(),isBefore(),isAfter(),isAdjacent(),isEmpty(),isBoundsValid(),equals() - Set operations :
union(),intersection(),difference(),gap() - Values :
length(),clamp(),random(),getLowerBoundValue(),getUpperBoundValue(),getStep() - Iteration :
generateSeries(),iterate()(lazy Generator),chunk() - Transformations :
split(),shift(),expand(),shrink(),scale(),clone(),__toString()/fromString()
DateRange also provides the fromMonth(), fromYear() and fromWeek() factories.
Quick Examples
IntRange Example
BigIntRange Example
DateRange Example
TimeRange Example
RangeCollection Example
Exceptions
InvalidArgumentException: Invalid range format, invalid value type, or unsupported operationInvalidBoundException: Invalid bounds (lower > upper)InvalidInfiniteBoundException: Infinite bound declared as inclusiveInvalidDateIntervalException: Invalid DateRange interval (time components in a step or offset, zero or negative step)InvalidTimeIntervalException: Invalid TimeRange interval (date components in a step or offset, zero or negative step)CantGenerateSeriesBecauseTheArrayIsTooLarge: Series too large to be generated (e.g. infinite bounds)
Notes
- Ranges can have infinite bounds (null)
- Bounds can be inclusive (
[,]) or exclusive ((,)) - An exclusive bound is shifted by one step: with a step of 5,
(0,20)has effective bounds 5 and 15 - Infinite bounds must be exclusive:
fromString()rejects[,10], andunion()/intersection()always produce exclusive infinite bounds - The step drives
length(),generateSeries(), and the effective value of exclusive bounds - Operations between ranges take the step into account:
union()/intersection()return null when the steps differ,equals()returns false