operator + method
Adds a Duration, Time, or int (ms) to the current instance, returning a new Time instance.
The behavior of the operator depends on the type of other:
- If
otherisnull, the current instance is returned. - If
otheris anint, it is interpreted as milliseconds and is added to the current instance. - If
otheris a Time or Duration instance, its added to the current instance.
Throws:
- A StateError if
otheris notnull,Time,int, orDuration.
Implementation
operator +(Object? other) {
if (other == null) return this;
if (other is Time) {
other = other.asDuration;
} else if (other is int) {
other = Duration(milliseconds: other);
}
if (other is Duration) {
if (other.inMicroseconds == 0) return this;
var t = asDuration + other;
return t.toTime();
}
throw StateError("Can't handle type: $other");
}