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

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

elephant-php/duration
=====================

Duration is a small immutable value object representing elapsed time.

0.1.0(1mo ago)05MITPHPPHP ^8.1

Since Apr 21Pushed 1mo agoCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

 [ ![elephant-php](elephant-php.webp) ](https://github.com/elephant-php/duration)

Duration
========

[](#duration)

A small immutable value object representing elapsed time.

 [![Latest Version](https://camo.githubusercontent.com/e57ea30a61442013491a9855e6759ff97976c39b7e991289c90e77b7e5f69699/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c657068616e742d7068702f6475726174696f6e2e737667)](https://packagist.org/packages/elephant-php/duration) [![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](./LICENSE.md) [![PHP 8.1+](https://camo.githubusercontent.com/63f4496656b9cc2ffb21b45d7017e6aee05d1c13f1b41d1e1c8b4d939c5e2708/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d3737376262342e737667)](https://www.php.net/releases/8.1/en.php)

Use cases
---------

[](#use-cases)

- Measuring execution time
- Logging
- Reporting
- Working with time differences

---

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

[](#installation)

```
composer require elephant-php/duration
```

Creation
--------

[](#creation)

from dates

```
use ElephantPhp\Duration\Duration;

$start    = new DateTimeImmutable('2026-01-01 10:00:00');
$end      = new DateTimeImmutable('2026-01-01 11:01:01');

$duration = Duration::between($start, $end);
```

from seconds

```
$duration = Duration::fromSeconds(3661);
```

from since to now

```
$duration = Duration::since($startedAt);
```

Access values
-------------

[](#access-values)

```
$duration->hours();
$duration->minutes();
$duration->seconds();
```

> ⚠️ **Note**`minutes()` and `seconds()` return remaining parts (0–59), not total values.

Total values
------------

[](#total-values)

```
$duration->toTotalSeconds();
$duration->toTotalMinutes();
$duration->toTotalHours();
```

Formatting
----------

[](#formatting)

```
// arguments are labels
$duration->format('h', 'm', 's'); // "1 h, 1 m, 1 s"

$duration->toHms();              // "01:01:01"
```

Example
-------

[](#example)

```
$duration = Duration::fromSeconds(3661);

echo $duration->format('h', 'm', 's'); // 1 h, 1 m, 1 s
echo $duration->toHms();               // 01:01:01

echo $duration->seconds();             // 1
echo $duration->minutes();             // 1
echo $duration->hours();               // 1

echo $duration->toTotalSeconds();      // 3661
echo $duration->toTotalMinutes();      // 61
echo $duration->toTotalHours();        // 1
```

License
-------

[](#license)

MIT License

Please see [`LICENSE`](./LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance91

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 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

49d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/98bd41d83d3ea8c774bfffa19be2323a844609643a8c4164bbb2ac9f74615923?d=identicon)[Pekhov Anton](/maintainers/Pekhov%20Anton)

---

Top Contributors

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

---

Tags

datetimedurationimmutablephpphp8timevalue-objectValue Objectvodurationno magic valueduration time

### Embed Badge

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

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

###  Alternatives

[moneyphp/money

PHP implementation of Fowler's Money pattern

4.8k88.3M492](/packages/moneyphp-money)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6249.3M51](/packages/knplabs-knp-time-bundle)[brick/date-time

Date and time library

3663.6M93](/packages/brick-date-time)[khill/php-duration

Converts between colon formatted time, human-readable time and seconds

1571.8M20](/packages/khill-php-duration)[ytake/valueobjects

A PHP library/collection of classes aimed to help developers using and undestanding immutable objects.(temporary package)

6086.5k1](/packages/ytake-valueobjects)[sybio/gif-frame-extractor

PHP class that separates all the frames (and their duration) of an animated GIF

179431.1k9](/packages/sybio-gif-frame-extractor)

PHPackages © 2026

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