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

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

khill/php-duration
==================

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

1.1.0(5y ago)1611.7M—0.2%25[4 PRs](https://github.com/kevinkhill/php-duration/pulls)20MITPHPPHP &gt;=5.4CI failing

Since Mar 17Pushed 2y ago5 watchersCompare

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

READMEChangelog (8)Dependencies (9)Versions (9)Used By (20)

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)

[![Total Downloads](https://camo.githubusercontent.com/e3c0afa6a8701d2d76e0d788d6965cdb74cbbeaa8c485a2c3316bff8ff00a4fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b68696c6c2f7068702d6475726174696f6e2e7376673f7374796c653d706c6173746963)](https://packagist.org/packages/khill/php-duration)[![License](https://camo.githubusercontent.com/c0a36de46681e85e588715728c9b6b532f7f140a0836a853cc63373d6793db89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68696c6c2f7068702d6475726174696f6e2e7376673f7374796c653d706c6173746963)](http://opensource.org/licenses/MIT)[![Minimum PHP Version](https://camo.githubusercontent.com/6b223721f6fed47957a7e9af6914307645af6c5c1d22ab909977ec494bf0a536/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e332d3838393242462e7376673f7374796c653d706c6173746963)](https://php.net/)[![PayPal](https://camo.githubusercontent.com/3ace80c744c83703a07e81b42be2c90b0259fd4c8be2fc7d08052307fee407d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d79656c6c6f772e7376673f7374796c653d706c6173746963)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FLP6MYY3PYSFQ)

[![Current Release](https://camo.githubusercontent.com/4593a16c34b781110779df31a34f256f75f24c2b8610bc1239c3fcf815a125c9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6b6576696e6b68696c6c2f7068702d6475726174696f6e2e7376673f7374796c653d706c6173746963)](https://github.com/kevinkhill/php-duration/releases)[![Build Status](https://camo.githubusercontent.com/0d9699d292a0b97e51903a7510b5ab995d30b2bbbad1ee66c526666934f3db7b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6b6576696e6b68696c6c2f7068702d6475726174696f6e2f6d61737465722e7376673f7374796c653d706c6173746963)](https://travis-ci.org/kevinkhill/php-duration)[![Coverage Status](https://camo.githubusercontent.com/2449551f15d7d368f124eef8326a14660188e3053b2aeb6893ca24fd657b25f7/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6b6576696e6b68696c6c2f7068702d6475726174696f6e2f6d61737465722e7376673f7374796c653d706c6173746963)](https://coveralls.io/r/kevinkhill/php-duration?branch=master)

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

46

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 65.4% 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 ~312 days

Recently: every ~411 days

Total

8

Last Release

1888d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f5001ed1fd24b718ba4ac61e00c76d8ed0408ec0ed428dfa79c6ff217ac02df?d=identicon)[kevinkhill](/maintainers/kevinkhill)

---

Top Contributors

[![kevinkhill](https://avatars.githubusercontent.com/u/266076?v=4)](https://github.com/kevinkhill "kevinkhill (34 commits)")[![pulzarraider](https://avatars.githubusercontent.com/u/960844?v=4)](https://github.com/pulzarraider "pulzarraider (11 commits)")[![dimitri-koenig](https://avatars.githubusercontent.com/u/4375825?v=4)](https://github.com/dimitri-koenig "dimitri-koenig (3 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)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (1 commits)")[![Ydalb](https://avatars.githubusercontent.com/u/1888805?v=4)](https://github.com/Ydalb "Ydalb (1 commits)")

---

Tags

durationhourminutesphpsecondsconverttimedurationseconds

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[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)
