FixedTimeProvider

Implementation of the current time provider which always returns a fixed value, useful for testing.

Constructors

this
this(SysTime currentTime)
Undocumented in source.

Members

Functions

incrementTime
void incrementTime(Duration dur)
Undocumented in source. Be warned that the author may not have intended to support it.
now
SysTime now()
Undocumented in source. Be warned that the author may not have intended to support it.
setTime
void setTime(SysTime newTime)
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From CurrentTimeProvider

now
SysTime now()

Gets the current system time.

Examples

Tests the functionality of the fixed time provider.

import core.thread;
SysTime time = SysTime(DateTime(2021, 9, 22, 22, 34, 57));
auto provider = new FixedTimeProvider(time);
assert(provider.now == time, "Fixed time provider's time does not match expected.");
Thread.sleep(seconds(1));
assert(provider.now == time, "Fixed time provider's time does not match expected.");

Meta