PHPackages                             dcarbone/gotime - 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. dcarbone/gotime

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

dcarbone/gotime
===============

Golang-like time class(es) for PHP 8.0+

v0.6.1(1y ago)2139.5k—8.1%1[1 PRs](https://github.com/dcarbone/gotime/pulls)2MITPHPPHP ^8.1CI passing

Since Dec 11Pushed 5mo ago1 watchersCompare

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

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

gotime
======

[](#gotime)

Golang-like time class(es) for PHP 8.1+

[![Tests](https://github.com/dcarbone/gotime/actions/workflows/tests.yml/badge.svg)](https://github.com/dcarbone/gotime/actions/workflows/tests.yml)

Desc
----

[](#desc)

The goal of this lib is to achieve near-enough (as determined by me) api equivalency in PHP to the GoLang Time package, as basically it is just better than PHP's.

Classes
-------

[](#classes)

### Duration

[](#duration)

The [Duration](src/Time/Duration.php) class is designed to emulate the golang [time.Duration](https://golang.org/src/time/time.go#L620) type.

There are 2 ways to construct a Duration class:

```
use \DCarbone\Go\Time;

$d = new Time\Duration(5 * Time::Second);
// produces a Duration with an internal value of 5e9;

$d = Time::ParseDuration('5s');
// produces a Duration with an internal value of 5e9;
```

Internally the "duration" is represented as an integer, allow for much fun.

#### Serialization

[](#serialization)

Assuming `$dt = new Time\Duration(5 * Time::Second);`:

TypeExecOutputJSON`echo json_encode($dt);``5000000000`string`echo (string)$dt;``5s`;#### DateInterval

[](#dateinterval)

[DateInterval](http://php.net/manual/en/class.dateinterval.php) pretty much sucks. I have created my own [DateInterval](src/Time/DateInterval.php) and [IntervalSpec](src/Time/IntervalSpec.php) classes to help alleviate this.

These provide [Duration](src/Time/Duration.php) the ability to create an interval for use with the standard [DateTime::add](http://php.net/manual/en/datetime.add.php) and [DateTime::sub](http://php.net/manual/en/datetime.sub.php) methods as such:

```
$dt = new \DateTime();
echo "{$dt->format('H:i:s')}\n";

$d = new Time\Duration(5 * Time::Second);
$dt->add($d->DateInterval());
echo "{$dt->format('H:i:s')}\n";

// 16:03:37
// 16:03:42
```

### Time

[](#time)

The [Time](src/Time/Time.php) class is designed to BARELY emulate the golang [time.Time](https://golang.org/src/time/time.go#L116) type. It's basically [DateTime](http://php.net/manual/en/class.datetime.php) with stuff on it. I consider it to be in a "beta" state.

There are 2 basic ways to construct a Time class:

```
use DCarbone\Go\Time;

// Returns an instance of Time\Time with an internal time of the unix epoch
$t = Time::New();

// Returns an instance of Time\Time with an internal time of whenever you constructed it.
$t = Time::Now();
```

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance61

Regular maintenance activity

Popularity35

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% 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 ~157 days

Recently: every ~379 days

Total

18

Last Release

407d ago

PHP version history (6 changes)0.1.0PHP &gt;=7.0

v0.4.0PHP &gt;=7.2

v0.4.2PHP &gt;=7.3

v0.4.6PHP ^7.3

v0.5.1PHP ^8.0

v0.6.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/385c0c0eae1b51f1e81ee464ff6bfb3cce32589ac252ca68cc3a8aec2e3ada14?d=identicon)[dcarbone](/maintainers/dcarbone)

---

Top Contributors

[![dcarbone](https://avatars.githubusercontent.com/u/1392439?v=4)](https://github.com/dcarbone "dcarbone (61 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![slt](https://avatars.githubusercontent.com/u/2295572?v=4)](https://github.com/slt "slt (1 commits)")

---

Tags

dateintervaldatetimedurationphptime

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dcarbone-gotime/health.svg)

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

###  Alternatives

[spatie/laravel-google-calendar

Manage events on a Google Calendar

1.4k1.5M21](/packages/spatie-laravel-google-calendar)[gajus/dindent

HTML indentation library for development and testing.

1781.9M50](/packages/gajus-dindent)[mindplay/php-vite

a lightweight PHP-backend integration for the Vite frontend build tool

6690.5k2](/packages/mindplay-php-vite)[contributte/forms-wizard

Wizard component for nette/forms

15783.7k](/packages/contributte-forms-wizard)[mvo/contao-group-widget

Adds a new group widget that allows repeating a set of DCA fields.

28124.3k31](/packages/mvo-contao-group-widget)

PHPackages © 2026

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