PHPackages                             p-sam/duration-immutable - 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. p-sam/duration-immutable

Abandoned → [p-sam/duration-immutable](/?search=p-sam%2Fduration-immutable)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

p-sam/duration-immutable
========================

Immutable class to store time durations

1.0.0(6y ago)17.2k↓87.5%MITPHPPHP &gt;=7.1

Since Jan 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/p-sam/php-duration-immutable)[ Packagist](https://packagist.org/packages/p-sam/duration-immutable)[ RSS](/packages/p-sam-duration-immutable/feed)WikiDiscussions develop Synced 1w ago

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

p-sam/duration-immutable
========================

[](#p-samduration-immutable)

[![license-badge](https://camo.githubusercontent.com/048f96de8ad6892cbad75e1ef3bc71581bb32a2faaf0a4d07905f664bfa28e27/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f702d73616d2f7068702d6475726174696f6e2d696d6d757461626c652e7376673f7374796c653d666c61742d737175617265)](LICENSE) [![release-version-badge](https://camo.githubusercontent.com/9241a557e64d4304721d798fc9981aaba1006f6e7f147c2334f355b2d0dd7503/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f702d73616d2f6475726174696f6e2d696d6d757461626c652e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/p-sam/duration-immutable) [![php-version-badge](https://camo.githubusercontent.com/75ec838fc749870851bf8d68970fba40f670c7050067ef97a2a4d4aa0b6f87c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f702d73616d2f6475726174696f6e2d696d6d757461626c652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/75ec838fc749870851bf8d68970fba40f670c7050067ef97a2a4d4aa0b6f87c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f702d73616d2f6475726174696f6e2d696d6d757461626c652e7376673f7374796c653d666c61742d737175617265)

Immutable PHP class to store time durations while not being tied to a Date.

Internally uses DateInterval and DateTime to do the actual operations.

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

[](#installation)

Install with composer:

```
$ composer require p-sam/duration-immutable

```

Usage
-----

[](#usage)

### Instanciating

[](#instanciating)

```
use SP\DurationImmutable\DurationImmutable;

DurationImmutable::fromSeconds(2); // 2s
DurationImmutable::fromSeconds(-30); // - 30s
DurationImmutable::fromSeconds(92, 0.200130); // 1m 32s 200ms 130µs

DurationImmutable::fromPHPDateInterval(new DateInterval('P1DT4H')); // 1d 4H
$refDate = DateTimeImmutable::createFromFormat(DateTimeImmutable::ATOM, '2020-01-10T00:00:00+00:00');
DurationImmutable::fromPHPDateInterval(
    new DateInterval('P1M3D'),
    $refDate
); // 34d

// refer to DateInterval::createFromDateString
// for documentation on accepted formats
DurationImmutable::fromHuman('1 hour - 15 minutes'); // 45m
DurationImmutable::fromHuman('yesterday'); // - 1d
```

### Ops

[](#ops)

```
use SP\DurationImmutable\DurationImmutable;

$duration = DurationImmutable::fromHuman('120 minutes'); // 2h

$duration->abs(); // 2h
$duration->add(DurationImmutable::fromHuman('30 minutes')); // 2h 30m
$duration->sub(DurationImmutable::fromHuman('3 hours + 10 minutes')); // - 1h 10m
$duration->mul(2.5); // 5h
$duration->div(-4); // - 30m

$dateTime = new DateTimeImmutable();
$duration->addTo($dateTime); // now + 2h

$duration->toSeconds(); // 7200
$duration->toIntervalSpec(); // "PT2H"
$duration->toPHPDateInterval(); // DateInterval("PT2H")
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

2311d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a88e68f5d890eb679cc6d569bf5d9bd02e79f909582dcda7809374f2dd3d43dd?d=identicon)[p-sam](/maintainers/p-sam)

---

Top Contributors

[![p-sam](https://avatars.githubusercontent.com/u/17620180?v=4)](https://github.com/p-sam "p-sam (4 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/p-sam-duration-immutable/health.svg)

```
[![Health](https://phpackages.com/badges/p-sam-duration-immutable/health.svg)](https://phpackages.com/packages/p-sam-duration-immutable)
```

###  Alternatives

[phar-io/manifest

Component for reading phar.io manifest information from a PHP Archive (PHAR)

7.5k744.7M26](/packages/phar-io-manifest)[symfony/rate-limiter

Provides a Token Bucket implementation to rate limit input and output in your application

27047.2M147](/packages/symfony-rate-limiter)[league/uri-components

URI components manipulation library

31932.3M67](/packages/league-uri-components)[phootwork/lang

Missing PHP language constructs

1224.8M8](/packages/phootwork-lang)

PHPackages © 2026

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