Clock class

Provides points in time relative to the current point in time, for example: now, 2 days ago, 4 weeks from now, etc.

This class is designed with testability in mind. The current point in time (or now()) is defined by a TimeFunction. By supplying your own time function or by using fixed clock (see constructors), you can control exactly what time a Clock returns and base your test expectations on that. See specific constructors for how to supply time functions.

Constructors

Clock([TimeFunction timeFunc = systemTime])
Creates a clock based on the given timeFunc. [...]
const
Clock.fixed(DateTime time)
Creates Clock that returns fixed time value. Useful in unit-tests.

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

ago({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, int milliseconds: 0, int microseconds: 0}) DateTime
Returns the point in time that's given amount of time ago. The amount of time is the sum of individual parts. Parts are compatible with ones defined in Duration.
agoBy(Duration duration) DateTime
Returns the point in time Duration amount of time ago.
daysAgo(int days) DateTime
Return the point in time days ago.
daysFromNow(int days) DateTime
Return the point in time days from now.
fromNow({int days: 0, int hours: 0, int minutes: 0, int seconds: 0, int milliseconds: 0, int microseconds: 0}) DateTime
Returns the point in time that's given amount of time from now. The amount of time is the sum of individual parts. Parts are compatible with ones defined in Duration.
fromNowBy(Duration duration) DateTime
Returns the point in time Duration amount of time from now.
hoursAgo(int hours) DateTime
Return the point in time hours ago.
hoursFromNow(int hours) DateTime
Return the point in time hours from now.
microsAgo(int micros) DateTime
Return the point in time micros microseconds ago.
microsFromNow(int micros) DateTime
Return the point in time micros microseconds from now.
millisAgo(int millis) DateTime
Return the point in time millis milliseconds ago.
millisFromNow(int millis) DateTime
Return the point in time millis milliseconds from now.
minutesAgo(int minutes) DateTime
Return the point in time minutes ago.
minutesFromNow(int minutes) DateTime
Return the point in time minutes from now.
monthsAgo(int months) DateTime
Return the point in time months ago on the same date.
monthsFromNow(int months) DateTime
Return the point in time months from now on the same date.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
now() DateTime
Returns current time.
secondsAgo(int seconds) DateTime
Return the point in time seconds ago.
secondsFromNow(int seconds) DateTime
Return the point in time seconds from now.
toString() String
Returns a string representation of this object.
inherited
weeksAgo(int weeks) DateTime
Return the point in time weeks ago.
weeksFromNow(int weeks) DateTime
Return the point in time weeks from now.
yearsAgo(int years) DateTime
Return the point in time years ago on the same date.
yearsFromNow(int years) DateTime
Return the point in time years from now on the same date.

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited