# Time Injected Clocks and Bounded Stopwatch Task ID: M-TIME-02 Phase: P1 Status: APPROVED Contracts: C-01, C-04, C-05 ## 1. Context and baseline `include/Void/Time/Stopwatch.hpp` hardcodes `std::chrono::steady_clock::now()`, grows `laps_` without bound, and lacks `resume()`. No injectable `MonotonicClock` / `CivilClock` / `ManualClock` interface exists yet for deterministic testing or Async deadlines. ## 2. Deliverables - `include/Void/Time/Clock.hpp` (`MonotonicClock`, `CivilClock`, `SystemMonotonicClock`, `SystemCivilClock`, `ManualClock`, `ManualCivilClock`, `remaining_until`). - Updated clock-injectable, bounded `Stopwatch` (`resume`, single-sample `split`, `try_lap` capped at 4,096) and `ScopedTimer` clock overload in `include/Void/Time/Stopwatch.hpp`. - `tests/standalone/Time/Clock.cpp` and deterministic tests in `tests/standalone/Time/Stopwatch.cpp`. ## 3. Exact files and interfaces - `include/Void/Time/Clock.hpp`: atomic nanosecond storage in `ManualClock`/`ManualCivilClock`, checked `advance` (`negative_step`, `overflow`), monotonic `set` in `ManualClock`, `remaining_until(clock, deadline)`. - `include/Void/Time/Stopwatch.hpp`: `StopwatchError { not_running, lap_limit_reached }`, `kDefaultMaxLaps = 4096`, borrowed `MonotonicClock` constructors, `resume()`, `try_lap()`, single-sample `split()`, legacy `lap()` compatibility. ## 4. Edge cases - `ManualClock::advance` with negative duration or `INT64_MAX` overflow leaves time unchanged and returns `ClockError`. - `Stopwatch::start() -> stop() -> advance(clock) -> resume()` preserves prior elapsed & laps without counting stopped idle time. - `try_lap()` at `max_laps_` returns `lap_limit_reached` without growing `laps_`. ## 5. Acceptance criteria - Existing sleep-based `Time`/`Stopwatch` tests pass; deterministic `ManualClock` tests run with zero sleeps under `-Werror`. ## 6. Verification commands ```sh dev cpp-gcc -c cmake -S . -B /tmp/void-p1-time -G Ninja -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Time;Testing" -DVOID_WARNINGS_AS_ERRORS=ON dev cpp-gcc -c cmake --build /tmp/void-p1-time --parallel 4 dev cpp-gcc -c /tmp/void-p1-time/tests/VoidTests --filter "Clock*|Stopwatch*|Time*" ```