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

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

componenta/clock
================

PSR-20 clock integration for Componenta

v1.0.0(1mo ago)092MITPHPPHP ^8.4

Since Jun 16Pushed 1mo agoCompare

[ Source](https://github.com/componenta/clock)[ Packagist](https://packagist.org/packages/componenta/clock)[ RSS](/packages/componenta-clock/feed)WikiDiscussions main Synced 1w ago

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

Componenta Clock
================

[](#componenta-clock)

PSR-20 clock and datetime factory abstractions for deterministic time handling.

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

[](#installation)

```
composer require componenta/clock
```

The package declares `Componenta\Clock\ConfigProvider` in `extra.componenta.config-providers`. When `componenta/composer-plugin` is installed, the provider is added to the generated provider list automatically.

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

[](#requirements)

- PHP 8.4+
- `psr/clock`

Related Packages
----------------

[](#related-packages)

PackageWhy it matters here`psr/clock`Defines `ClockInterface` for domain and application code.`componenta/di`Registers `ClockInterface` and `DateTimeFactoryInterface` through `ConfigProvider`.`componenta/cqrs`Commands and handlers can depend on clocks instead of constructing time directly.`componenta/session`Can use time for TTL, activity, and expiration logic.What It Provides
----------------

[](#what-it-provides)

- `Clock`: minimal UTC PSR-20 clock.
- `DateTimeFactoryInterface`: PSR-20 clock plus date creation methods.
- `DateTimeFactory`: production datetime factory with timezone support.
- `FrozenClock`: deterministic test clock and factory.
- Typed exceptions for invalid timezones and datetime parsing failures.

DateTimeFactory
---------------

[](#datetimefactory)

```
use Componenta\Clock\DateTimeFactory;

$clock = new DateTimeFactory('Europe/Kaliningrad');

$now = $clock->now();
$today = $clock->today();
$fromTimestamp = $clock->fromTimestamp(1_700_000_000);
$parsed = $clock->parse('2026-06-07 12:00:00');
$fromFormat = $clock->fromFormat('Y-m-d', '2026-06-07');
```

The configured timezone is exposed as a read-only property:

```
$clock->timezone->getName();
```

Change timezone immutably:

```
$utc = $clock->withTimezone('UTC');
```

`withTimezone()` returns the same instance when the requested timezone is already active.

FrozenClock
-----------

[](#frozenclock)

Use `FrozenClock` in tests or deterministic workflows.

```
use Componenta\Clock\FrozenClock;

$clock = new FrozenClock('2026-06-07 12:00:00', 'UTC');

$clock->now();      // fixed point in time
$clock->advance('+1 day');
$clock->freeze('2026-06-10 09:00:00');
```

DI Registration
---------------

[](#di-registration)

`ConfigProvider` registers:

- `DateTimeFactory::class` factory
- `Psr\Clock\ClockInterface` alias to `DateTimeFactoryInterface`
- `DateTimeFactoryInterface` alias to `DateTimeFactory`

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance91

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

43d ago

### Community

Maintainers

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

---

Top Contributors

[![Shelamkoff](https://avatars.githubusercontent.com/u/20490712?v=4)](https://github.com/Shelamkoff "Shelamkoff (1 commits)")

### Embed Badge

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

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

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[ecotone/ecotone

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

564576.7k54](/packages/ecotone-ecotone)[symfony/clock

Decouples applications from the system clock

433205.7M430](/packages/symfony-clock)[lcobucci/clock

Yet another clock abstraction

799207.5M168](/packages/lcobucci-clock)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

378604.0k107](/packages/flow-php-etl)[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.5k1.5M108](/packages/mcp-sdk)

PHPackages © 2026

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