CloudCastle Clock

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

FrozenClock — frozen clock

Purpose

Test determinism: time stands still until explicitly moved with setTo()/modify()/advance()/rewind().

What for and how to use

The basic unit-test tool: FrozenClock::from('2026-01-01 00:00:00', 'UTC'); snapshot any clock with $clock->freeze().

Example

$clock = FrozenClock::from('2026-01-01 00:00:00', 'UTC');
$clock->advance(90.0);            // +90 seconds
$clock->modify('+1 day');
$clock->rewind(30.0);             // 30 seconds back

Anti-patterns

Never use in production: stopped time breaks TTLs and schedules.

Lifecycle

stateDiagram-v2
    [*] --> Frozen: from()/fromUtcNow()
    Frozen --> Frozen: now() (same moment)
    Frozen --> Shifted: advance()/rewind()/modify()/setTo()
    Shifted --> Shifted: now() (new fixed moment)

Feature comparison with competitors

Aspect🏆 CloudCastlesymfonycarbonlcobuccibesteergebnis
Explicit forward and backward shifts✅❌❌❌❌❌
String modifiers (+1 day)✅❌✅❌❌❌
Typed error on garbage input✅❌✅❌❌❌
Snapshot from any clock (freeze())✅❌❌❌❌❌
Total🏆 402000

← Back to the feature list


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