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

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

matthewdavis/duration
=====================

A package to handle durations with ease.

v1.0.2(7y ago)11101MITPHPPHP &gt;=7.0

Since Mar 18Pushed 7y ago2 watchersCompare

[ Source](https://github.com/mdavis1982/duration)[ Packagist](https://packagist.org/packages/matthewdavis/duration)[ RSS](/packages/matthewdavis-duration/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/83b30bf1c5046659471663f039b420cbde0182395536d1f82bb987b3e960ccc0/68747470733a2f2f7472617669732d63692e6f72672f6d6461766973313938322f6475726174696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mdavis1982/duration)

Duration
========

[](#duration)

Duration is a PHP library for converting between different types of durations.

For example, you might want to cache something for 2 days, but your cache configuration is in seconds. Duration makes this super easy to read in your code and does away with the magic numbers.

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

[](#installation)

Install the package using Composer:

```
composer require matthewdavis/duration
```

Usage
-----

[](#usage)

```
use MatthewDavis\Duration\Duration;

$seconds = Duration::days(3)->inSeconds(); // 259,200
```

The library has the following static constructors:

```
// Seconds
Duration::second();
Duration::seconds(int $seconds);

// Minutes
Duration::minute();
Duration::minutes(int $minutes);

// Hours
Duration::hour();
Duration::hours(int $hours);

// Days
Duration::day();
Duration::days(int $days);

// Weeks
Duration::week();
Duration::weeks(int $weeks);
```

You can convert between any of the units by using the getter methods:

```
$duration = Duration::week();

$duration->inSeconds(); // 604,800
$duration->inMinutes(); // 10,080
$duration->inHours();   // 168
$duration->inDays();    // 7
$duration->inWeeks();   // 1
```

You can also chain the call (as you would likely do when setting a config value):

```
// In some configuration file...
'cache_ttl' => Duration::days(2)->inSeconds(),
```

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License
-------

[](#license)

[MIT](./LICENSE.md)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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 ~0 days

Total

3

Last Release

2614d ago

### Community

Maintainers

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

---

Top Contributors

[![mdavis1982](https://avatars.githubusercontent.com/u/199807?v=4)](https://github.com/mdavis1982 "mdavis1982 (8 commits)")[![damonjones](https://avatars.githubusercontent.com/u/154075?v=4)](https://github.com/damonjones "damonjones (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[eftec/statemachineone

A state Machine library for business processes

1144.0k](/packages/eftec-statemachineone)[johndoh/globaladdressbook

Adds global address books to Roundcube

706.0k](/packages/johndoh-globaladdressbook)

PHPackages © 2026

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