Timespan class Relative times
A duration of time with nanosecond precision.
This represents a duration of time equal to
seconds + nanosecondPart * 10^-9 seconds.
The component numbers will always be normalized as follows:
-10^9< nanosecondPart <10^9- seconds.sign == nanosecondPart.sign
There are two important differences between this and Duration:
precision and longest representable timespan. This has nanosecond
precision vs. microsecond for Duration, and it can represent
much longer time spans (read on for details).
Longest Timespan
The longest representable timespans are a bit complicated.
This stores two ints: one for the number of seconds, and one for a
nanosecond fraction of seconds. Dart's
maximum int size varies,
but you can count on at least 53 bits. Since Timespan dedicates a full
int to seconds it can cover at least 2^53 seconds, which is roughly 200
million years.
With that said, other factors will limit the practical maximum. In particular, conversion operations like inMicroseconds and date arithmetic could overflow.
- Implemented types
- Annotations
-
- @immutable
Constructors
- Timespan({int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0, int nanoseconds = 0})
-
Constructs a
Timespan.factory - Timespan.fromDuration(Duration duration)
-
Constructs a
Timespanfrom a Duration.factory - Timespan.parse(String periodString)
-
Parses an ISO 8601 period string.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- inDays → int
-
Gets the timespan in days.
no setter
- inHours → int
-
Gets the timespan in hours.
no setter
- inMicroseconds → int
-
Gets the timespan in microseconds.
no setter
- inMilliseconds → int
-
Gets the timespan in milliseconds.
no setter
- inMinutes → int
-
Gets the timespan in minutes.
no setter
- inNanoseconds → int
-
Gets the timespan in nanoseconds.
no setter
- inSeconds → int
-
Gets the timespan in seconds.
no setter
- isNegative → bool
-
Determines if the timespan is negative.
no setter
- nanosecondPart → int
-
The fractional part of the number of seconds in nanoseconds.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- seconds → int
-
The whole number of seconds.
final
Methods
-
abs(
) → Timespan -
Returns the absolute value of this
Timespan. -
compareTo(
Timespan other) → int -
Compares this to another
Timespan.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDuration(
) → Duration - Converts this to a duration with a loss of precision.
-
toString(
) → String -
Returns a string formatted as an ISO 8601 time duration.
override
Operators
-
operator *(
num other) → Timespan - Multiplication operator. Fractional results are rounded towards zero.
-
operator +(
Timespan other) → Timespan - Addition operator.
-
operator -(
Timespan other) → Timespan - Subtraction operator.
-
operator <(
Timespan other) → bool - Less than operator.
-
operator <=(
Timespan other) → bool - Less than or equal operator.
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
Timespan other) → bool - Greater than operator.
-
operator >=(
Timespan other) → bool - Greater than or equal operator.
-
operator unary-(
) → Timespan - Unary negation operator.
-
operator ~/(
num other) → Timespan - Integer division operator.