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

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

differentweb/php-duration
=========================

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

1.1.0(1y ago)03.4k↓34.6%MITPHPPHP &gt;=5.4

Since Mar 17Pushed 1y agoCompare

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

READMEChangelog (1)Dependencies (8)Versions (10)Used By (0)

Changes:

Quantities greater than 99X are managed

PHP-Duration
============

[](#php-duration)

#### Convert durations between colon formatted time, human-readable time and seconds

[](#convert-durations-between-colon-formatted-time-human-readable-time-and-seconds)

This package was created with a very specific goal in mind, to enable an easy way for users to input how long something took, as a duration of time.

The library can accept either in colon separated format, like 2:43 for 2 minutes and 43 seconds OR written as human readable or abbreviated time, such as 6m21s for 6 minutes and 21 seconds.

Both can be converted into seconds and minutes with precision for easy storage into a database.

Seconds, colon separated, abbreviated, all three can be parsed and interchanged.

- supports hours, minutes, and seconds (with microseconds)
- humanized input supports any form of the words "hour", "minute", "seconds"
    - Example, you could input 1h4m2s or 4 Hr. 32 Min.

Install
=======

[](#install)

```
composer require khill/php-duration:~1.0
```

Usage
=====

[](#usage)

```
use Khill\Duration\Duration;

$duration = new Duration('7:31');

echo $duration->humanize();  // 7m 31s
echo $duration->formatted(); // 7:31
echo $duration->toSeconds(); // 451
echo $duration->toMinutes(); // 7.5166
echo $duration->toMinutes(null, 0); // 8
echo $duration->toMinutes(null, 2); // 7.52
```

```
$duration = new Duration('1h 2m 5s');

echo $duration->humanize();  // 1h 2m 5s
echo $duration->formatted(); // 1:02:05
echo $duration->toSeconds(); // 3725
echo $duration->toMinutes(); // 62.0833
echo $duration->toMinutes(null, 0); // 62
```

```
// Configured for 6 hours per day
$duration = new Duration('1.5d 1.5h 2m 5s', 6);

echo $duration->humanize();  // 1d 4h 32m 5s
echo $duration->formatted(); // 10:32:05
echo $duration->toSeconds(); // 37925
echo $duration->toMinutes(); // 632.083333333
echo $duration->toMinutes(null, 0); // 632
```

```
$duration = new Duration('4293');

echo $duration->humanize();  // 1h 11m 33s
echo $duration->formatted(); // 1:11:33
echo $duration->toSeconds(); // 4293
echo $duration->toMinutes(); // 71.55
echo $duration->toMinutes(null, 0); // 72
```

Note
====

[](#note)

You do not have to create a new object for each conversion, you can also pass any of the three forms into any of the methods to get the immediate output.

```
$duration = new Duration;

echo $duration->humanize('1h 2m 5s');  // 1h 2m 5s
echo $duration->formatted('1h 2m 5s'); // 1:02:05
echo $duration->toSeconds('1h 2m 5s'); // 3725
echo $duration->toMinutes('1h 2m 5s'); // 62.0833
echo $duration->toMinutes('1h 2m 5s', true); // 62
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 52.5% 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 ~501 days

Recently: every ~741 days

Total

8

Last Release

571d ago

### Community

Maintainers

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

---

Top Contributors

[![kevinkhill](https://avatars.githubusercontent.com/u/266076?v=4)](https://github.com/kevinkhill "kevinkhill (32 commits)")[![pulzarraider](https://avatars.githubusercontent.com/u/960844?v=4)](https://github.com/pulzarraider "pulzarraider (11 commits)")[![furlo82](https://avatars.githubusercontent.com/u/58848618?v=4)](https://github.com/furlo82 "furlo82 (11 commits)")[![dimitri-koenig](https://avatars.githubusercontent.com/u/4375825?v=4)](https://github.com/dimitri-koenig "dimitri-koenig (3 commits)")[![Ydalb](https://avatars.githubusercontent.com/u/1888805?v=4)](https://github.com/Ydalb "Ydalb (1 commits)")[![differentweb](https://avatars.githubusercontent.com/u/34447656?v=4)](https://github.com/differentweb "differentweb (1 commits)")[![joMpire](https://avatars.githubusercontent.com/u/23141202?v=4)](https://github.com/joMpire "joMpire (1 commits)")[![AntonLazarev](https://avatars.githubusercontent.com/u/1969866?v=4)](https://github.com/AntonLazarev "AntonLazarev (1 commits)")

---

Tags

converttimedurationseconds

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[khill/php-duration

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

1611.7M20](/packages/khill-php-duration)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6308.9M39](/packages/knplabs-knp-time-bundle)[symfony/clock

Decouples applications from the system clock

431168.9M205](/packages/symfony-clock)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[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)
