Clock class
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.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
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
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.
-
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
. -
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 microseconds) → DateTime -
Return the point in time
microseconds
ago. -
microsFromNow(
int microseconds) → DateTime -
Return the point in time
microseconds
from now. -
millisAgo(
int milliseconds) → DateTime -
Return the point in time
milliseconds
ago. -
millisFromNow(
int milliseconds) → DateTime -
Return the point in time
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 nonexistent 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. -
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
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 ==(
Object other) → bool -
The equality operator.
inherited