AdjustableTimeProvider class

Mutable time source for tests and deterministic flows.

USAGE EXAMPLE:

final tp = AdjustableTimeProvider(initialEpochSeconds: 1_700_000_000);
expect(tp.nowEpochSeconds(), 1700000000);
tp.advance(seconds: 45);
expect(tp.nowEpochSeconds(), 1700000045);
tp.setNow(epochSeconds: 1700001000);

SECURITY NOTE:

  • Never use this provider in production; it is meant for tests only.
Implemented types

Constructors

AdjustableTimeProvider.new({required int initialEpochSeconds})
Creates an adjustable provider at the given initialEpochSeconds (UTC).

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

advance({required int seconds}) → void
Advances time by seconds (can be negative to move backwards).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
nowEpochSeconds() int
Returns the current mocked UNIX time in seconds (UTC).
override
setNow({required int epochSeconds}) → void
Sets the current mocked time to epochSeconds (UTC).
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited