PHPackages                             componenta/duration - 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. componenta/duration

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

componenta/duration
===================

Immutable ISO 8601 duration value object

v1.0.0(1mo ago)00MITPHPPHP ^8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/duration)[ Packagist](https://packagist.org/packages/componenta/duration)[ RSS](/packages/componenta-duration/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Componenta Duration
===================

[](#componenta-duration)

Immutable ISO 8601 duration value object with calendar-aware and fixed-duration operations.

Use it when application code needs a typed duration instead of passing raw seconds or raw ISO strings.

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

[](#installation)

```
composer require componenta/duration
```

Related Packages
----------------

[](#related-packages)

This package is standalone.

PackageWhy it may be used nearby`componenta/clock`Provides reference dates for calendar-aware comparisons.`componenta/config`Can store ISO 8601 durations that are converted to `Duration`.`componenta/validation`Can validate user strings before creating the value object.Usage
-----

[](#usage)

```
use Componenta\Stdlib\Duration;

$duration = Duration::fromISO8601('PT90S');

$duration->toISO8601(); // "PT1M30S"
$duration->toSeconds(); // 90
$duration->humanize();  // "1 minute 30 seconds"
```

Factories are available for common units:

```
Duration::ofDays(2);
Duration::ofHours(6);
Duration::fromSeconds(3600);
Duration::between($start, $end);
```

Calendar Components
-------------------

[](#calendar-components)

Years and months are calendar components. They are not converted to seconds without a reference date because their exact length depends on the calendar.

```
$duration = Duration::ofMonths(1);

$duration->hasCalendarComponents(); // true
$duration->isFixed();               // false
$duration->toSeconds();             // throws RuntimeException
$duration->toSecondsFrom(new DateTimeImmutable('2026-01-01'));
```

Weeks are expanded to days when parsing ISO 8601 because the value object stores days, not a separate week component.

Arithmetic
----------

[](#arithmetic)

`Duration` supports immutable arithmetic:

- `add`
- `subtract`
- `subtractClamped`
- `multiply`
- `divideBy`
- `sum`
- `min`
- `max`

Use `compareTo()` only for comparable durations. Calendar-aware comparison is available through `compareToFrom()` with a reference date.

Conversion
----------

[](#conversion)

The object can convert to:

- ISO 8601 string
- `DateInterval`
- dense array through `toArray()`
- sparse array through `toSparseArray()`
- custom string through `format()`
- JSON through `jsonSerialize()`

`applyTo()` adds the duration to a `DateTimeInterface` and returns a `DateTimeImmutable`.

Supported Format
----------------

[](#supported-format)

The parser supports integer ISO 8601 components: `P[n]Y[n]M[n]W[n]DT[n]H[n]M[n]S`.

Fractional components such as `PT1.5S` are rejected.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance91

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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

43d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20490712?v=4)[Andrey Shelamkoff](/maintainers/Shelamkoff)[@Shelamkoff](https://github.com/Shelamkoff)

---

Top Contributors

[![Shelamkoff](https://avatars.githubusercontent.com/u/20490712?v=4)](https://github.com/Shelamkoff "Shelamkoff (1 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/componenta-duration/health.svg)

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

###  Alternatives

[norkunas/youtube-dl-php

youtube-dl / yt-dlp wrapper for php

514356.8k18](/packages/norkunas-youtube-dl-php)[theodo-evolution/legacy-wrapper-bundle

40124.9k](/packages/theodo-evolution-legacy-wrapper-bundle)

PHPackages © 2026

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