CloudCastle Clock

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

StepClock — step clock

Purpose

Every now() call advances time by a fixed step: a deterministic sequence of moments without manual advance().

What for and how to use

Generating event series in tests: record timestamps, polling intervals. peek()/timestamp() observe without advancing.

Example

$clock = StepClock::from('2026-01-01 00:00:00', TimeSpan::ofSeconds(10), 'UTC');
$clock->now();   // 00:00:00
$clock->now();   // 00:00:10
$clock->peek();  // 00:00:20 — without advancing

Anti-patterns

Remember: only now() advances; use a zero step to “stop”.

Lifecycle

stateDiagram-v2
    [*] --> S0: from(start, step)
    S0 --> S1: now() → start
    S1 --> S2: now() → start+step
    S2 --> S3: now() → start+2·step
    S1 --> S1: peek()/timestamp() (no advance)

Feature comparison with competitors

Aspect🏆 CloudCastlesymfonycarbonlcobuccibesteergebnis
Auto-step on every now()✅❌❌❌❌❌
peek() without advancing✅❌❌❌❌❌
Negative/zero step✅❌❌❌❌❌
Step as nanosecond-precision TimeSpan✅❌❌❌❌❌
Total🏆 400000

← Back to the feature list


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