Clock class Null safety
A provider for the "current time" and points relative to the current time.
This class is designed with testability in mind. The current point in time (or now()) is defined by a function that returns a DateTime. By supplying your own time function or using new Clock.fixed, you can control exactly what time a Clock returns and base your test expectations on that.
Most users should use the top-level clock field, which provides access to a default implementation of Clock which can be overridden using withClock.
Constructors
- Clock([DateTime currentTime() = systemTime])
-
Creates a clock based on the given
currentTime, or on the system clock by default.const - Clock.fixed(DateTime time)
-
Creates Clock that always considers the current time to be
time.
Properties
- hashCode → int
-
The hash code for this object.
read-onlyinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
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.
-
agoBy(
Duration duration) → DateTime - Returns the point in time Duration amount of time ago.
-
daysAgo(
int days) → DateTime -
Return the point in time
daysago. -
daysFromNow(
int days) → DateTime -
Return the point in time
daysfrom 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.
-
fromNowBy(
Duration duration) → DateTime - Returns the point in time Duration amount of time from now.
-
getStopwatch(
) → Stopwatch -
Returns a new stopwatch that uses the current time as reported by
this.Deprecated('Use stopwatch() instead.')">@Deprecated('Use stopwatch() instead.') -
hoursAgo(
int hours) → DateTime -
Return the point in time
hoursago. -
hoursFromNow(
int hours) → DateTime -
Return the point in time
hoursfrom now. -
microsAgo(
int microseconds) → DateTime -
Return the point in time
microsecondsago. -
microsFromNow(
int microseconds) → DateTime -
Return the point in time
microsecondsfrom now. -
millisAgo(
int milliseconds) → DateTime -
Return the point in time
millisecondsago. -
millisFromNow(
int milliseconds) → DateTime -
Return the point in time
millisecondsfrom now. -
minutesAgo(
int minutes) → DateTime -
Return the point in time
minutesago. -
minutesFromNow(
int minutes) → DateTime -
Return the point in time
minutesfrom now. -
monthsAgo(
int months) → DateTime -
Return the point in time
monthsago on the same date. -
monthsFromNow(
int months) → DateTime -
Return the point in time
monthsfrom 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
secondsago. -
secondsFromNow(
int seconds) → DateTime -
Return the point in time
secondsfrom now. -
stopwatch(
) → Stopwatch -
Returns a new stopwatch that uses the current time as reported by
this. -
toString(
) → String -
A string representation of this object.
inherited
-
weeksAgo(
int weeks) → DateTime -
Return the point in time
weeksago. -
weeksFromNow(
int weeks) → DateTime -
Return the point in time
weeksfrom now. -
yearsAgo(
int years) → DateTime -
Return the point in time
yearsago on the same date. -
yearsFromNow(
int years) → DateTime -
Return the point in time
yearsfrom now on the same date.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited