Skip to main content

Module simulator

Module simulator 

Source
Expand description

Time simulation for deterministic testing.

This module provides a simulated time system where time progression is controlled programmatically via step counters and multipliers. This enables deterministic testing of time-dependent code.

Time simulation is based on three components:

  • Epoch offset - The base Unix timestamp in milliseconds
  • Step counter - The current simulation step
  • Step multiplier - How many milliseconds of simulated time pass per step

Simulated time is calculated as: epoch_offset + (step * step_multiplier)

Structs§

RealTime
Marker type for temporarily using real system time instead of simulated time.

Functions§

current_step
Returns the current simulation step.
datetime_local_now
Returns the current simulated local date and time, or real time if in a with_real_time context.
datetime_utc_now
Returns the current simulated UTC date and time, or real time if in a with_real_time context.
epoch_offset
Returns the current epoch offset in milliseconds.
instant_now
Returns a simulated monotonic instant, or real instant if in a with_real_time context.
next_step
Advances the simulation to the next step.
now
Returns the current simulated system time, or real time if in a with_real_time context.
reset_epoch_offset
Resets the epoch offset to a new random value.
reset_step
Resets the simulation step counter to zero.
reset_step_multiplier
Resets the step multiplier to a new random value.
set_step
Sets the current simulation step to the specified value.
step_multiplier
Returns the current step multiplier in milliseconds per step.
with_real_time
Executes a function using real system time instead of simulated time.