CloudCastle Clock

🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano

Clock — static facade

Purpose

Short names for typical scenarios: Clock::now(), Clock::utc(), Clock::mock(), Clock::frozen(), factories for all decorators. Declared as a case-less enum — instantiation is impossible at the language level.

What for and how to use

Simple scripts and migrating legacy to managed time; Clock::now('+1 hour') returns a DatePoint.

Example

Clock::now();                       // current moment of the global clock
Clock::utc()->timestamp();
Clock::step('2026-01-01', 5.0);     // StepClock
Clock::queue('10:00', '10:05');     // QueueClock
Clock::adapt($psrClock);            // PsrClockAdapter

Anti-patterns

With DI prefer injecting ClockInterface directly — the facade hides the dependency.

Lifecycle

flowchart TD
    F[Clock facade] --> A[system/utc/inZone]
    F --> B[frozen/mock/monotonic]
    F --> C[offset/scaled/truncatedTo]
    F --> D[step/queue/adapt]
    F --> E[now → ClockHolder]

Feature comparison with competitors

Aspect🏆 CloudCastlesymfonycarbonlcobuccibesteergebnis
Single entry point to all implementations✅❌❌❌❌❌
Non-instantiable (enum)✅❌❌❌❌❌
now() with a modifier → DatePoint✅❌❌❌❌❌
Global clock under the hood✅✅✅❌❌❌
Total🏆 411000

← Back to the feature list


🇷🇺 Русский · 🇬🇧 English · 🇩🇪 Deutsch · 🇫🇷 Français · 🇪🇸 Español · 🇮🇹 Italiano