PHPackages                             withinboredom/time - 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. withinboredom/time

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

withinboredom/time
==================

Converting time to units

v6.0.0(11mo ago)152.7k6[1 PRs](https://github.com/withinboredom/time/pulls)1MITPHPPHP ^8.4CI passing

Since Mar 20Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/withinboredom/time)[ Packagist](https://packagist.org/packages/withinboredom/time)[ RSS](/packages/withinboredom-time/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (1)

An advanced library offering type safety and identity with Durations
====================================================================

[](#an-advanced-library-offering-type-safety-and-identity-with-durations)

Identity
--------

[](#identity)

This library uses some tricks to intern values so that two times are always equal to one another, no matter the distance in time or space.

```
use Withinboredom\Time;
use Withinboredom\Time\Unit;

$hour = Time::from(Unit::Hours, 1);
$minutes = Time::from(Unit::Minutes, 60);

echo $hour === $minutes ? 'true' : 'false'
// outputs: true
```

Type Safety
-----------

[](#type-safety)

You can ensure nobody will accidentally confuse seconds with milliseconds or minutes with seconds:

```
function sleep(Time $time): void {
    \sleep($time->as(Unit::Seconds));
}

// Helper functions are included so you can type less code:
sleep(Minutes(5));
```

Conversions and Math
--------------------

[](#conversions-and-math)

You can easily convert between units and even perform operations, like sorting and arithmetic:

```
// use the hour constant to get one hour
$hour = Hour;

$hour = $hour->multiply(10)->add(Minutes(10)); // get 10:10 hours

$interval = $hour->toDateInterval();

echo Hours(10) < $hour ? 'true' : 'false';
// output: true
```

Support for Crell\\Serde
------------------------

[](#support-for-crellserde)

You cannot serialize/deserialize/clone `Time` objects. However, if you use something like Serde, you can still serialize your value objects:

```
class CacheItem {
    public function __construct(
        #[Field('expiration_in_seconds')]
        #[TimeAs(Unit::Seconds)]
        public Time $expiration,
    ) {}
}

$serde = new SerdeCommon(handlers: new \Withinboredom\Time\SerdeExporter());
$serde->serialize(new CacheItem(Minutes(5)), 'json');
```

The above will be serialized (and deserialized) from:

```
{
    "expiration_in_seconds": 300
}
```

Units
-----

[](#units)

- Nanoseconds
- Microseconds
- Milliseconds
- Minutes
- Hours
- Days
- Weeks

FAQ
---

[](#faq)

> Why not months/years?

There are no set days in a month/year, so it’s better to use `DateInterval` for those types of measures.

> Why does this exist?

I don’t like [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)#:~:text=Magic%20numbers%20are%20common%20in%20programs%20across%20many,have%20such%20constants%20that%20identify%20the%20contained%20data.).

> How performant is this?

The main overhead is in autoloading and function-call overhead. Thus, if realtime performance is a concern, you might want to stick to magic numbers.

Developing
----------

[](#developing)

If you wish to create a PR or update the code here:

1. Clone the repo
2. `composer install` to install test dependencies
3. `yarn` to install git hooks for formatting
4. Open in favorite IDE.

Code Standards
--------------

[](#code-standards)

[Per](https://www.php-fig.org/per/coding-style/) coding styles are followed.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance73

Regular maintenance activity

Popularity29

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 92.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 ~97 days

Recently: every ~110 days

Total

13

Last Release

347d ago

Major Versions

v1.0 → v2.02022-03-20

v2.1 → v3.02024-02-23

v3.1.1 → v4.0.02024-03-05

v4.1.0 → v5.0.02024-07-10

v5.0.0 → v6.0.02025-05-27

PHP version history (3 changes)v4.1.0PHP ^8.0

v5.0.0PHP ^8.2

v6.0.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f5995953815a492e3bf6276044042d84035247139141ec7fd013c13af4e6dd4?d=identicon)[withinboredom](/maintainers/withinboredom)

---

Top Contributors

[![withinboredom](https://avatars.githubusercontent.com/u/1883296?v=4)](https://github.com/withinboredom "withinboredom (26 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

php-libraryphp8time

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/withinboredom-time/health.svg)

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

###  Alternatives

[phpcr/phpcr-migrations

Migrations for PHPCR

421.4M2](/packages/phpcr-phpcr-migrations)

PHPackages © 2026

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