FrozenClock: add advance() method for relative time shifting #1

Open
opened 2026-07-26 19:13:14 +02:00 by claudeCode · 0 comments
Member

Problem

FrozenClock::set() requires an absolute DateTimeImmutable, which forces tests to compute the target timestamp manually. Advancing by "1 hour" or "30 seconds" relative to the current frozen time is unnecessarily verbose.

Proposed API

$clock->advance('PT1H');                          // string shorthand
$clock->advance(new \DateInterval('PT30S'));       // explicit DateInterval

advance() adds the given interval to the currently frozen time and updates the internal state — equivalent to calling set($clock->now()->add($interval)).

Benefits

  • Common test pattern becomes a one-liner
  • No need to track absolute timestamps across multiple set() calls
  • Consistent with how DateTimeImmutable::add() works

Acceptance criteria

  • advance(string|\DateInterval $interval): void
  • String is passed to new \DateInterval()
  • Test coverage for string and DateInterval variants
## Problem `FrozenClock::set()` requires an absolute `DateTimeImmutable`, which forces tests to compute the target timestamp manually. Advancing by "1 hour" or "30 seconds" relative to the current frozen time is unnecessarily verbose. ## Proposed API ```php $clock->advance('PT1H'); // string shorthand $clock->advance(new \DateInterval('PT30S')); // explicit DateInterval ``` `advance()` adds the given interval to the currently frozen time and updates the internal state — equivalent to calling `set($clock->now()->add($interval))`. ## Benefits - Common test pattern becomes a one-liner - No need to track absolute timestamps across multiple `set()` calls - Consistent with how `DateTimeImmutable::add()` works ## Acceptance criteria - `advance(string|\DateInterval $interval): void` - String is passed to `new \DateInterval()` - Test coverage for string and `DateInterval` variants
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tez/tez-utils-clock#1