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

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

dgame/php-time
==============

php time conversion

v0.7.0(4y ago)2105.3k↓26.5%MITPHPPHP 8.0

Since Jun 18Pushed 4y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (15)Versions (12)Used By (0)

php-time
========

[](#php-time)

Convert TimeUnits to other TimeUnits in no time.
------------------------------------------------

[](#convert-timeunits-to-other-timeunits-in-no-time)

### Seconds:

[](#seconds)

```
seconds(300)->inMinutes()->equalsAmount(5);
```

#### Minutes:

[](#minutes)

```
minutes(60)->inSeconds()->equalsAmount(3600);
minutes(60)->inHours()->equalsAmount(1);
```

#### Hours:

[](#hours)

```
hours(24)->inMinutes()->equalsAmount(1440);
hours(24)->inDays()->equalsAmount(1);
```

### Days:

[](#days)

```
days(7)->inHours()->equalsAmount(168);
days(7)->inWeeks()->equalsAmount(1);
```

### Weeks:

[](#weeks)

```
weeks(12)->inDays()->equalsAmount(84);
```

### Months:

[](#months)

```
months(12)->inYears()->equalsAmount(1);
```

### Years:

[](#years)

```
years(1)->inWeeks()->equalsAmount(52);
years(2)->inMonths()->equalsAmount(24);
```

Compare TimeUnits:
------------------

[](#compare-timeunits)

```
hours(24)->equals(days(1));
days(1)->equals(hours(24));
years(1)->equals(days(365));
weeks(1)->equals(days(7));
```

Add / Subtract TimeUnits:
-------------------------

[](#add--subtract-timeunits)

```
days(1)->add(hours(24))->equals(days(2));
hours(24)->subtract(days(0.5))->equals(hours(12));
hours(1)->equals(minutes(60));
```

---

Get specific informations about a Month / Year
----------------------------------------------

[](#get-specific-informations-about-a-month--year)

There is a **Month** and a **Year** class (note the missing `s` at the end) to access precise informations about a specific year or a specific month in a specific year:

### Month:

[](#month)

```
Month::Of('Feb', 2015)->inDays()->equalsAmount(28);
Month::Of('Feb', 2015)->inWeeks()->equalsAmount(4);
Month::Of('Feb', 2016)->inDays()->equalsAmount(29);
Month::Of('Jun', 2016)->inDays()->equalsAmount(30);
Month::Of('Jun', 2016)->inWeeks()->equalsAmount(4.28571);
```

### Year:

[](#year)

```
Year::Of(2016)->isLeapyear();
Year::Of(2015)->inDays()->equalsAmount(365);
Year::Of(2016)->inDays()->equalsAmount(366);
Year::Of(2015)->inWeeks()->equalsAmount(52.142857142857);
Year::Of(2016)->inWeeks()->equalsAmount(52.285714285714);
```

---

Represent a TimeUnit in individual units
----------------------------------------

[](#represent-a-timeunit-in-individual-units)

```
$unit = new TimeUnits(days(1000));

$this->assertTrue($unit->getYears()->equalsAmount(2));
$this->assertTrue($unit->getMonths()->equalsAmount(8));
$this->assertTrue($unit->getWeeks()->equalsAmount(3));
$this->assertTrue($unit->getDays()->equalsAmount(5));
$this->assertTrue($unit->getHours()->equalsAmount(11));
$this->assertTrue($unit->getMinutes()->equalsAmount(33));
$this->assertTrue($unit->getSeconds()->equalsAmount(20));
```

```
$unit = new TimeUnits(hours(4.5));

$this->assertTrue($unit->getYears()->equalsAmount(0));
$this->assertTrue($unit->getMonths()->equalsAmount(0));
$this->assertTrue($unit->getWeeks()->equalsAmount(0));
$this->assertTrue($unit->getDays()->equalsAmount(0));
$this->assertTrue($unit->getHours()->equalsAmount(4));
$this->assertTrue($unit->getMinutes()->equalsAmount(30));
$this->assertTrue($unit->getSeconds()->equalsAmount(0));
```

```
$unit = new TimeUnits(minutes(525));

$this->assertTrue($unit->getYears()->equalsAmount(0));
$this->assertTrue($unit->getMonths()->equalsAmount(0));
$this->assertTrue($unit->getWeeks()->equalsAmount(0));
$this->assertTrue($unit->getDays()->equalsAmount(0));
$this->assertTrue($unit->getHours()->equalsAmount(8));
$this->assertTrue($unit->getMinutes()->equalsAmount(45));
$this->assertTrue($unit->getSeconds()->equalsAmount(0));
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~185 days

Recently: every ~384 days

Total

11

Last Release

1765d ago

PHP version history (4 changes)v0.1.0PHP &gt;=7.0

0.5.0PHP ^7.0

v0.6.0PHP &gt;=7.1

v0.7.0PHP 8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a9fa98c1a3e70a521430fc2fba266657b2c981b5d8a36bf236fad01f9846dcd?d=identicon)[Dgame](/maintainers/Dgame)

---

Top Contributors

[![Dgame](https://avatars.githubusercontent.com/u/2406877?v=4)](https://github.com/Dgame "Dgame (66 commits)")

---

Tags

phptimetimeunitclocktimedatetimerTime conversion

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/clock

Decouples applications from the system clock

431168.9M205](/packages/symfony-clock)[knplabs/knp-time-bundle

Making your dates and durations look sensible and descriptive

6308.9M39](/packages/knplabs-knp-time-bundle)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[icecave/chrono

A date &amp; time library that is decoupled from the system clock.

54188.9k7](/packages/icecave-chrono)[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)

PHPackages © 2026

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