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
timevalue. Useful in unit-tests.
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. 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
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. 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
hoursago. -
hoursFromNow(
int hours) → DateTime -
Return the point in time
hoursfrom now. -
microsAgo(
int micros) → DateTime -
Return the point in time
microsmicroseconds ago. -
microsFromNow(
int micros) → DateTime -
Return the point in time
microsmicroseconds from now. -
millisAgo(
int millis) → DateTime -
Return the point in time
millismilliseconds ago. -
millisFromNow(
int millis) → DateTime -
Return the point in time
millismilliseconds from 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 nonexistent 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. -
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