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

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

philiprehberger/php-human-duration
==================================

Convert seconds into human-readable duration strings

v1.0.2(1mo ago)11[1 PRs](https://github.com/philiprehberger/php-human-duration/pulls)MITPHPPHP ^8.2CI passing

Since Mar 13Pushed 1mo agoCompare

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

READMEChangelogDependencies (3)Versions (4)Used By (0)

PHP Human Duration
==================

[](#php-human-duration)

[![Tests](https://github.com/philiprehberger/php-human-duration/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-human-duration/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/3cb1abb7393643d85268c552f7fa5284ae9a4b03f8d2b3427fcec5f0c0567f51/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d68756d616e2d6475726174696f6e2e737667)](https://packagist.org/packages/philiprehberger/php-human-duration)[![License](https://camo.githubusercontent.com/2e6b9225ec51415919a4475cf8bb497f407469cca962acc21a539ce79b936df2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7068696c69707265686265726765722f7068702d68756d616e2d6475726174696f6e)](LICENSE)

Convert seconds into human-readable duration strings.

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

[](#requirements)

- PHP 8.2+

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

[](#installation)

```
composer require philiprehberger/php-human-duration
```

Usage
-----

[](#usage)

### Creating Durations

[](#creating-durations)

```
use PhilipRehberger\HumanDuration\Duration;

// From seconds
$duration = Duration::fromSeconds(3665);

// From minutes
$duration = Duration::fromMinutes(90);

// From hours
$duration = Duration::fromHours(2.5);

// From the difference between two dates
$duration = Duration::between(
    new DateTimeImmutable('2026-01-01 08:00:00'),
    new DateTimeImmutable('2026-01-01 09:30:00'),
);
```

### Formatting Durations

[](#formatting-durations)

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

$duration->toHuman();   // "1h 1m 5s"
$duration->toVerbose(); // "1 hour, 1 minute, 5 seconds"
$duration->toCompact(); // "1:01:05"

// Stringable — casting to string uses toHuman()
echo $duration; // "1h 1m 5s"
```

### Accessing Raw Values

[](#accessing-raw-values)

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

$duration->totalSeconds(); // 5400
$duration->totalMinutes(); // 90.0
$duration->totalHours();   // 1.5
```

### Negative Durations

[](#negative-durations)

```
$duration = Duration::fromSeconds(-65);

$duration->toHuman();   // "-1m 5s"
$duration->toVerbose(); // "-1 minute, 5 seconds"
$duration->toCompact(); // "-1:05"
```

API
---

[](#api)

MethodReturnDescription`Duration::fromSeconds(int $seconds)``Duration`Create from seconds`Duration::fromMinutes(int|float $minutes)``Duration`Create from minutes`Duration::fromHours(int|float $hours)``Duration`Create from hours`Duration::between(DateTimeInterface $start, DateTimeInterface $end)``Duration`Create from date difference`toHuman()``string`Compact format: `1h 5m 30s``toVerbose()``string`Verbose format: `1 hour, 5 minutes, 30 seconds``toCompact()``string`Clock format: `1:05:30``totalSeconds()``int`Total seconds`totalMinutes()``float`Total minutes`totalHours()``float`Total hoursDevelopment
-----------

[](#development)

```
composer install
vendor/bin/phpunit
vendor/bin/pint --test
vendor/bin/phpstan analyse
```

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

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

Total

3

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd7d24cbbf32400fa13ce0bbe7a31edd2d66a6d4488eafdb3d64c5337bf0435?d=identicon)[philiprehberger](/maintainers/philiprehberger)

---

Top Contributors

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

---

Tags

formattimereadabledurationhuman

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6308.9M39](/packages/knplabs-knp-time-bundle)[brick/date-time

Date and time library

3623.3M60](/packages/brick-date-time)[khill/php-duration

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

1611.7M20](/packages/khill-php-duration)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1831.1M18](/packages/consistence-consistence)[danielstjules/php-pretty-datetime

Generates human-readable strings for PHP DateTime objects

5791.9k](/packages/danielstjules-php-pretty-datetime)[sybio/gif-frame-extractor

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

179417.2k8](/packages/sybio-gif-frame-extractor)

PHPackages © 2026

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