PHPackages                             intriro/clock - 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. intriro/clock

ActiveLibrary

intriro/clock
=============

A simple wrapper for abstracting the system date

2.0.0(5y ago)08.6k↓100%MITPHPPHP &gt;=7.4

Since Dec 20Pushed 5y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (7)Used By (0)

Clock
=====

[](#clock)

A simple clock abstraction library for PHP.

Motivation
==========

[](#motivation)

The problem with DateTime instances is that they are not testable and mockable. They always rely on the system date and time. Therefore you should never directly create DateTime instances.

With the Clock interface you are able to switch implementations and therefore have control over the returned DateTime instances.

Installation
============

[](#installation)

Install it using Composer.

```
composer require intriro/clock

```

Implementation
==============

[](#implementation)

The `Clock` object provides access to the current date and time. Basically it is just a object which returns a DateTimeImmutable instance that represents the current date and time.

With a Clock interface you can always swap implementations and get DateTimeImmutable instances which don't rely on the system time.

The library ships with a `Clock` interface and three implementations.

`SystemClock` gives you access to the system date and time. It just returns `new DateTimeImmutable('now')` and it's the default implementation.

`ShiftedSystemClock` returns the system date and time that is shifted for a provided interval.

`FixedClock` returns a predefined fixed date and time.

Example
=======

[](#example)

```
class Event
{
    /**
     * @var DateTimeImmutable
     */
    private $date;

    public function hasPassed(Clock $clock): bool
    {
        if ($this->clock->now() > $this->date) {
            return true;
        }

        return false;
    }
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

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 ~261 days

Recently: every ~327 days

Total

6

Last Release

2120d ago

Major Versions

0.1.1 → 1.0.02017-09-19

1.1.1 → 2.0.02020-07-20

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

2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/380fd037fb71854d3d53a7713137bb38385b5ecea2419917032c6f40ce3d681c?d=identicon)[intriro](/maintainers/intriro)

---

Top Contributors

[![alsar](https://avatars.githubusercontent.com/u/1380676?v=4)](https://github.com/alsar "alsar (13 commits)")

### Embed Badge

![Health badge](/badges/intriro-clock/health.svg)

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

PHPackages © 2026

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