PHPackages                             mawebdk/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. [Testing &amp; Quality](/categories/testing)
4. /
5. mawebdk/clock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mawebdk/clock
=============

Representation of a clock with easy mocking of current date and time for testing.

1.0.1(1y ago)0231BSD-2-ClausePHPPHP ^8.3.6

Since Feb 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mawebdk/clock)[ Packagist](https://packagist.org/packages/mawebdk/clock)[ RSS](/packages/mawebdk-clock/feed)WikiDiscussions main Synced today

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

clock
=====

[](#clock)

This package contains a representation of a clock with easy mocking of current date and time for testing.

Usage
-----

[](#usage)

Obtain the current UTC date and time as a DateTimeImmutable object.

```
$currentUtcDateTime = Clock::getSingleton()->now();

```

Mocking of current UTC date and time
------------------------------------

[](#mocking-of-current-utc-date-and-time)

Use ReflectionClass to set the Clock singleton to a mocked class implementing ClockInterface.

```
/**
 * @throws Exception
 */
public function testMocking()
{
    $mockedDateTimeImmutable = DateTimeImmutable::createFromFormat(
        format: 'Y-m-d H:i:s.u',
        datetime: '1999-12-31 23:59:59.999999',
        timezone: new DateTimeZone(timezone: 'UTC')
    );

    $mockedClock = $this->createMock(type: ClockInterface::class);
    $mockedClock
        ->method(constraint: 'now')
        ->willReturn($mockedDateTimeImmutable);

    $reflectionClass = new ReflectionClass(objectOrClass: Clock::class);
    $reflectionClass->setStaticPropertyValue(name: 'singleton', value: $mockedClock);

    $this->assertSame(
        expected: $mockedDateTimeImmutable->format(format: 'Y-m-d H:i:s.u'),
        actual: Clock::getSingleton()->now()->format(format: 'Y-m-d H:i:s.u')
    );
}

```

Remember to reset singleton to ensure usage of correct date and time in subsequent tests.

```
protected function tearDown(): void
{
    // Reset singleton to ensure usage of correct date and time in subsequent tests.
    $reflectionClass = new ReflectionClass(objectOrClass: Clock::class);
    $reflectionClass->setStaticPropertyValue(name: 'singleton', value: null);
}

```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance42

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Total

2

Last Release

473d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/176606063?v=4)[mawebdk](/maintainers/mawebdk)[@mawebdk](https://github.com/mawebdk)

---

Top Contributors

[![mawebdk](https://avatars.githubusercontent.com/u/176606063?v=4)](https://github.com/mawebdk "mawebdk (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[spomky-labs/otphp

A PHP library for generating one time passwords according to RFC 4226 (HOTP Algorithm) and the RFC 6238 (TOTP Algorithm) and compatible with Google Authenticator

1.5k50.3M168](/packages/spomky-labs-otphp)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

185701.7M5.6k](/packages/nesbot-carbon)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k51](/packages/ecotone-ecotone)[simplesamlphp/saml2

SAML2 PHP library from SimpleSAMLphp

30418.0M43](/packages/simplesamlphp-saml2)

PHPackages © 2026

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