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

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

kcs/php-duration
================

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

v2.0.0(1y ago)062MITPHPPHP ^8.2

Since Mar 17Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (5)Versions (10)Used By (0)

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)

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.

This library is a revamped/revised/updated version of the khill/php-duration library.

Install
-------

[](#install)

```
composer require kcs/php-duration
```

Usage
-----

[](#usage)

```
use Kcs\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(0); // 8
echo $duration->toMinutes(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(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(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(0); // 72
```

Utilities
---------

[](#utilities)

This package contains some utility classes to help integration with other libraries:

- `Kcs\Duration\Doctrine\DurationType`: doctrine type to help using the duration class with doctrine ORM and DBAL
- `Kcs\Duration\Serializer\DurationHandler`: (de-)serialization handler to use with `kcs/serializer` library

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 63% 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 ~432 days

Recently: every ~638 days

Total

9

Last Release

616d ago

Major Versions

1.1.0 → v2.0.02024-09-09

PHP version history (2 changes)1.1.0PHP &gt;=5.4

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/73dd7f3bebd03ec946b6b12359141ea461b770c3671acac4e8004e3c2d78e78f?d=identicon)[alekitto](/maintainers/alekitto)

---

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)")[![alekitto](https://avatars.githubusercontent.com/u/1257206?v=4)](https://github.com/alekitto "alekitto (2 commits)")[![joMpire](https://avatars.githubusercontent.com/u/23141202?v=4)](https://github.com/joMpire "joMpire (1 commits)")[![lloricode](https://avatars.githubusercontent.com/u/8251344?v=4)](https://github.com/lloricode "lloricode (1 commits)")[![AntonLazarev](https://avatars.githubusercontent.com/u/1969866?v=4)](https://github.com/AntonLazarev "AntonLazarev (1 commits)")[![Ydalb](https://avatars.githubusercontent.com/u/1888805?v=4)](https://github.com/Ydalb "Ydalb (1 commits)")

---

Tags

converttimedurationseconds

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/kcs-php-duration/health.svg)](https://phpackages.com/packages/kcs-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

430168.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)
