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

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

tobento/service-clock
=====================

PSR-20 clocks for PHP applications.

2.0(7mo ago)02538MITPHPPHP &gt;=8.4

Since Jun 22Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/service-clock)[ Packagist](https://packagist.org/packages/tobento/service-clock)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-service-clock/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (8)

Cache Service
=============

[](#cache-service)

Providing [PSR-20](https://www.php-fig.org/psr/psr-20) clocks for PHP applications.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting started](#getting-started)
    - [Requirements](#requirements)
    - [Highlights](#highlights)
- [Documentation](#documentation)
    - [Available Clocks](#available-clocks)
        - [System Clock](#system-clock)
        - [Frozen Clock](#frozen-clock)
- [Credits](#credits)

---

Getting started
===============

[](#getting-started)

Add the latest version of the clock service project running this command.

```
composer require tobento/service-clock

```

Requirements
------------

[](#requirements)

- PHP 8.4 or greater

Highlights
----------

[](#highlights)

- Framework-agnostic, will work with any project
- Decoupled design

Documentation
=============

[](#documentation)

Available Clocks
----------------

[](#available-clocks)

### System Clock

[](#system-clock)

The system clock relies on the current system time. If the `timezone` parameter is not defined it uses the timezone from the `date_default_timezone_get` method.

```
use Tobento\Service\Clock\SystemClock;
use Psr\Clock\ClockInterface;

$clock = new SystemClock();

var_dump($clock instanceof ClockInterface);
// bool(true)
```

**With defined timezone parameter**

```
use Tobento\Service\Clock\SystemClock;
use DateTimeZone;

$clock = new SystemClock(
    timezone: 'UTC'
);

$clock = new SystemClock(
    timezone: new DateTimeZone('Europe/Berlin')
);
```

### Frozen Clock

[](#frozen-clock)

The frozen clock will always return the same date time, suitable for testing. If the `now` parameter is not defined it uses the current time of the [System Clock](#system-clock).

```
use Tobento\Service\Clock\FrozenClock;
use Psr\Clock\ClockInterface;

$clock = new FrozenClock();

var_dump($clock instanceof ClockInterface);
// bool(true)

// Modify the clock returning a new instance.
// Will accept all formats supported by DateTimeImmutable::modify()
$clockNew = $clock->modify('+30 seconds');

// With a new timezone returning a new instance.
$clockNew = $clock->withTimeZone(timezone: 'UTC');
```

**With defined now parameter**

```
use Tobento\Service\Clock\FrozenClock;
use Tobento\Service\Clock\SystemClock;
use Psr\Clock\ClockInterface;
use DateTimeImmutable;

$clock = new FrozenClock(
    now: new DateTimeImmutable()
);

// or from another clock:
$clock = new FrozenClock(
    now: new SystemClock()
);
```

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance63

Regular maintenance activity

Popularity15

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity63

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

Total

4

Last Release

228d ago

Major Versions

1.x-dev → 2.02025-09-24

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

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (3 commits)")

---

Tags

phppackageclockpsr-20tobento

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[beste/clock

A collection of Clock implementations

7423.3M20](/packages/beste-clock)

PHPackages © 2026

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