PHPackages                             wmde/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. wmde/clock

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

wmde/clock
==========

Simple interface to get the current time without binding to global system resources. Includes test doubles!

2.0.0(1y ago)380.4k↑220.1%1BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since Sep 26Pushed 2d ago21 watchersCompare

[ Source](https://github.com/wmde/Clock)[ Packagist](https://packagist.org/packages/wmde/clock)[ RSS](/packages/wmde-clock/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)Dependencies (3)Versions (8)Used By (1)

Clock
=====

[](#clock)

A simple interface to get the current time without binding to global system resources, plus configurable implementations that you can use in your unit tests.

Clock Usage
-----------

[](#clock-usage)

```
function yourCode(Clock $clock) {
    $time = $clock->now(); // Returns DateTimeImmutable. More testable than initializing a new instance
}
```

Clock interface:

```
interface Clock {
    public function now(): \DateTimeImmutable;
}
```

Provided implementations:

- `SystemClock`: Uses global system resources
- `StubClock`: Returns value provided in the constructor. Useful in tests
- `CollectionClock`: Returns specified values sequentially. Useful in tests
- `IncrementingClock`: Returns an incremented starting time infinitely. Useful in tests

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

[](#installation)

To use the Clock library in your project, add a dependency on wmde/clock to your project's `composer.json` file. Here is a minimal example of a `composer.json`file that just defines a dependency on Clock 1.x:

```
{
    "require": {
        "wmde/clock": "~1.0"
    }
}
```

Development
-----------

[](#development)

For development you need to have Docker and the `docker compose` plugin installed. Local PHP and Composer are not needed.

### Installing the development dependencies

[](#installing-the-development-dependencies)

To pull in the project dependencies (PHPUnit, PHPStan, etc.) via Composer, run:

```
make install-php

```

To update the dependencies, run

```
make update-php

```

### Running the CI checks

[](#running-the-ci-checks)

To run all CI checks, which includes PHPUnit tests, PHPCS style checks and coverage tag validation, run:

```
make

```

### Running the tests

[](#running-the-tests)

To run only the PHPUnit tests run

```
make test

```

To run only a subset of PHPUnit tests or otherwise pass flags to PHPUnit, run

```
docker-compose run --rm app ./vendor/bin/phpunit --filter SomeClassNameOrFilter

```

Release notes
-------------

[](#release-notes)

### 2.0.0 (2025-04-22)

[](#200-2025-04-22)

Updated dev dependencies and increased PHP version requirements (to exert some pressure to update PHP).

### 1.0.0 (2018-09-26)

[](#100-2018-09-26)

Initial release with `Clock`, `SystemClock`, `StubClock`, `CollectionClock` and `IncrementingClock`

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance75

Regular maintenance activity

Popularity34

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

2

Last Release

436d ago

Major Versions

1.0.0 → 2.0.02025-04-23

PHP version history (2 changes)1.0.0PHP &gt;=5.6

2.0.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

![](https://www.gravatar.com/avatar/054adb441e7ee248ec924bc45fa793835c284710eb31627587fa5de21bab9e96?d=identicon)[wmde](/maintainers/wmde)

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

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (47 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (47 commits)")[![gbirke](https://avatars.githubusercontent.com/u/223326?v=4)](https://github.com/gbirke "gbirke (19 commits)")[![moiikana](https://avatars.githubusercontent.com/u/11670701?v=4)](https://github.com/moiikana "moiikana (15 commits)")[![Sperling-0](https://avatars.githubusercontent.com/u/30310702?v=4)](https://github.com/Sperling-0 "Sperling-0 (6 commits)")[![Abban](https://avatars.githubusercontent.com/u/663782?v=4)](https://github.com/Abban "Abban (5 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[ultra-lite/container

2119.4k1](/packages/ultra-lite-container)[defiant/randomorg

PHP class and Laravel implementation for Random.org

162.5k](/packages/defiant-randomorg)

PHPackages © 2026

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