Clock class abstract

IClock is intended for use anywhere you need to have access to the current time. Although it's not strictly incorrect to call SystemClock.Instance.GetCurrentInstant() directly, in the same way as you might call DateTime.UtcNow, it's strongly discouraged as a matter of style for production code. We recommend providing an instance of IClock to anything that needs it, which allows you to write tests using the fake clock in the TimeMachine.Testing assembly (or your own implementation).

see also:

Implementers

Constructors

Clock()

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

getCurrentInstant() Instant
Gets the current Instant on the time line according to this clock. Returns the current instant on the time line according to this clock.
inTzdbSystemDefaultZone() Future<ZonedClock>
Constructs a ZonedClock from a clock (the target of the method), in the TZDB mapping for the system default time zone time zone and the ISO calendar system.
inUtc() ZonedClock
Constructs a ZonedClock from a clock (the target of the method), using the UTC time zone and ISO calendar system.
inZone(DateTimeZone zone, [CalendarSystem? calendar]) ZonedClock
Constructs a ZonedClock from a clock (the target of the method), a time zone, and a calendar system.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

current Clock
The default Clock is the SystemClock but can be changed by the user. This is used for Instant.now. Replacing this with FakeClock can be useful for testing.
getter/setter pair