Standard Library
interface IClock
What a program may know about the time.
since 0.1.0-alpha.1linuxwindowswasm
Overview
A function that takes an IClock parameter does not read the real clock directly, so a test
can pass a clock that always returns the same moment. use std::IClock; makes the real
clock (SystemClock) the default for such parameters.
Examples
class FixedClock : IClock {
int ms;
new FixedClock(int t) { ms = t; }
int now() => ms;
}
bind IClock => FixedClock(86400000);
void report(IClock clock) {
int days = clock.now() / 86400000;
console.writeln("day number ${days}");
}
report();
day number 1
Methods
now
now() -> intThe current time as milliseconds since 1 January 1970 UTC.
Returns
The number of milliseconds since the Unix epoch.
Examples
class Stopped : IClock {
int now() => 5000;
}
IClock clock = Stopped();
console.writeln(clock.now() / 1000);
5
See also
- SystemClock — The real clock behind the
IClockinterface.