PHPackages                             superscript/monetary-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. superscript/monetary-interval

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

superscript/monetary-interval
=============================

0.1.2(10mo ago)028.0k↑65.9%2MITPHPPHP ^8.3CI passing

Since Apr 2Pushed 10mo agoCompare

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

READMEChangelog (2)Dependencies (7)Versions (6)Used By (2)

Monetary Interval Library
=========================

[](#monetary-interval-library)

A PHP library for working with monetary intervals. It provides an elegant way to create, compare, and work with intervals of monetary values using standard interval notation.

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

[](#installation)

Install the package via Composer:

```
composer require gosuperscript/monetary-interval
```

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Usage
-----

[](#usage)

### Creating Intervals

[](#creating-intervals)

You can create intervals from string notation:

```
use Superscript\MonetaryInterval\MonetaryInterval;

// Create from string notation
$interval = MonetaryInterval::fromString('[USD 1.00,USD 5.00]');  // Closed interval
$interval = MonetaryInterval::fromString('(USD 1.00,USD 5.00)');  // Open interval
$interval = MonetaryInterval::fromString('[USD 1.00,USD 5.00)');  // Right-open interval
$interval = MonetaryInterval::fromString('(USD 1.00,USD 5.00]');  // Left-open interval
$interval = MonetaryInterval::fromString('[USD 1.00,)');      // Left-bounded interval (infinite upper bound)
$interval = MonetaryInterval::fromString('(,USD 1.00]');      // Right-bounded interval (infinite lower bound)
```

### Interval Notation

[](#interval-notation)

The library supports four types of interval notation:

- `[a,b]` - **Closed interval**: includes both monetary endpoints `a` and `b`. Example: `[USD 1.00,USD 5.00]` includes all values from USD 1.00 to USD 5.00.
- `(a,b)` - **Open interval**: excludes both monetary endpoints `a` and `b`. Example: `(USD 1.00,USD 5.00)` includes all values greater than USD 1.00 and less than USD 5.00.
- `[a,b)` - **Right-open interval**: includes `a` but not `b`. Example: `[USD 1.00,USD 5.00)` includes USD 1.00 and all values up to (but not including) USD 5.00.
- `(a,b]` - **Left-open interval**: excludes `a` but includes `b`. Example: `(USD 1.00,USD 5.00]` includes all values greater than USD 1.00 up to and including USD 5.00.

The inclusion or exclusion of the endpoints determines how comparisons behave. For example, if an interval is `(USD 1.00,USD 5.00)`, calling `$interval->isGreaterThan('USD 1.00')` will return `true` because USD 1.00 is not part of the interval. However, if the interval is `[USD 1.00,USD 5.00]`, then `$interval->isGreaterThanOrEqualTo('USD 1.00')` will return `true` since USD 1.00 is included.

Understanding this notation is crucial for interpreting comparison behavior correctly.

The library also supports unbounded intervals using empty endpoints. These are interpreted as extending to infinity:

- `[a,)` - Left-bounded interval: includes `a` and extends infinitely to the right.
- `(,b]` - Right-bounded interval: includes `b` and extends infinitely to the left.
- `(,)` - Fully unbounded interval: represents all monetary values.

Internally, unbounded sides are represented using `PHP_INT_MIN` or `PHP_INT_MAX`.

### Canonical Money Format

[](#canonical-money-format)

Monetary values in this library follow the canonical money format: `CUR 0.00` — where:

- `CUR` is a 3-letter ISO 4217 currency code (e.g., `USD`, `EUR`, `GBP`)
- A space separates the currency code from the numeric value
- The amount uses two decimal places for clarity and consistency

For example:

- `USD 10.00` represents 10 US Dollars
- `EUR 0.99` represents 99 Euro cents

This notation ensures compatibility with [brick/money](https://github.com/brick/money) and safe handling of currency math.

### Interval Comparisons

[](#interval-comparisons)

```
$interval = MonetaryInterval::fromString('[USD 2.00,USD 5.00]');

$interval->isGreaterThan('USD 1.00');      // true
$interval->isGreaterThanOrEqualTo('USD 2.00');  // true
$interval->isLessThan('USD 6.00');         // true
$interval->isLessThanOrEqualTo('USD 5.00');     // true
```

Comparisons such as `$interval->isGreaterThan($amount)` evaluate whether *all* monetary values within the interval are greater than the specified amount. So `[USD 2.00,USD 5.00]` is greater than `USD 1.00` (because every value from USD 2.00 to USD 5.00 is greater than USD 1.00), but not greater than `USD 2.00` unless the interval is open on the left side (e.g., `(USD 2.00,USD 5.00)`).

Similarly, `$interval->isLessThan($amount)` checks whether all values in the interval are less than the specified amount. `(USD 1.00,USD 5.00)` is less than `USD 6.00`, but not less than `USD 5.00` unless the interval excludes `USD 5.00` (e.g., `(USD 1.00,USD 5.00)` or `[USD 1.00,USD 5.00)`.

This logic allows for precise control over monetary comparisons, especially when you want to reason about bounds inclusivity.

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

This includes:

- Static analysis (`composer test:types`)
- Unit tests with coverage (`composer test:unit`)
- Mutation testing (`composer test:infection`)

License
-------

[](#license)

MIT

About
-----

[](#about)

This package is developed and maintained by Superscript. This package uses [brick/money](https://github.com/brick/money) for safe monetary value handling.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance54

Moderate activity, may be stable

Popularity29

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

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 ~46 days

Total

3

Last Release

319d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9832602d5b04f09fa5bd162acbaf87b0e5c50ce9a96b970424e78a3830695eb1?d=identicon)[robertvansteen](/maintainers/robertvansteen)

---

Top Contributors

[![robertvansteen](https://avatars.githubusercontent.com/u/14931924?v=4)](https://github.com/robertvansteen "robertvansteen (8 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/superscript-monetary-interval/health.svg)

```
[![Health](https://phpackages.com/badges/superscript-monetary-interval/health.svg)](https://phpackages.com/packages/superscript-monetary-interval)
```

###  Alternatives

[phpdocumentor/reflection-docblock

With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.

9.4k722.2M1.2k](/packages/phpdocumentor-reflection-docblock)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[sylius/promotion

Flexible promotion management for PHP applications.

28477.8k9](/packages/sylius-promotion)[sylius/taxonomy

Taxonomies - categorization of domain models in PHP projects.

14435.6k10](/packages/sylius-taxonomy)[wwwision/dcb-eventstore

Implementation of the Dynamic Consistency Boundary pattern described by Sara Pellegrini

2131.5k10](/packages/wwwision-dcb-eventstore)

PHPackages © 2026

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