PHPackages                             gosuperscript/schema-interval - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. gosuperscript/schema-interval

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

gosuperscript/schema-interval
=============================

A PHP library that extends gosuperscript/axiom with support for Interval types, providing type-safe interval handling and operator overloading for schema validation

v0.3.0(3mo ago)01.6k[2 PRs](https://github.com/gosuperscript/axiom-interval/pulls)MITPHPPHP ^8.4CI passing

Since Jun 19Pushed 3mo agoCompare

[ Source](https://github.com/gosuperscript/axiom-interval)[ Packagist](https://packagist.org/packages/gosuperscript/schema-interval)[ RSS](/packages/gosuperscript-schema-interval/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (9)Used By (0)

Axiom Interval
==============

[](#axiom-interval)

A PHP library that extends [gosuperscript/axiom](https://github.com/gosuperscript/axiom) with support for [Interval](https://github.com/superscript/interval) types, providing type-safe interval handling and operator overloading for schema validation.

Features
--------

[](#features)

- **Interval Type**: Transform and validate interval values in your schemas
- **Operator Overloading**: Compare intervals with numeric values using standard comparison operators (`>`, `=`, `transform('[1,2]');
$interval = $result->unwrap()->unwrap();

// Transform from Interval object
$interval = new Interval(
    BigNumber::of(1),
    BigNumber::of(2),
    IntervalNotation::Closed
);
$result = $type->transform($interval);

// Compare two intervals
$a = $type->transform('[1,2]')->unwrap()->unwrap();
$b = $type->transform('[1,2]')->unwrap()->unwrap();
$isEqual = $type->compare($a, $b); // true

// Format interval back to string
$formatted = $type->format($interval); // "[1,2]"
```

#### Interval Notation

[](#interval-notation)

Intervals can be specified using standard mathematical notation:

- `[1,2]` - Closed interval (includes both endpoints)
- `(1,2)` - Open interval (excludes both endpoints)
- `[1,2)` - Half-open interval (includes left, excludes right)
- `(1,2]` - Half-open interval (excludes left, includes right)

### Operator Overloading

[](#operator-overloading)

The `IntervalOverloader` class enables comparison operations between intervals and numeric values:

```
use Superscript\Axiom\Interval\Operators\IntervalOverloader;
use Superscript\Interval\Interval;

$overloader = new IntervalOverloader();
$interval = Interval::fromString('[2,3]');

// Check if operator is supported
$supports = $overloader->supportsOverloading($interval, 1, '>'); // true

// Evaluate comparisons
$overloader->evaluate($interval, 1, '>');   // true (interval is greater than 1)
$overloader->evaluate($interval, 2, '>=');  // true (interval is >= 2)
$overloader->evaluate($interval, 3, '
