operator + method

dynamic operator +(
  1. Object? other
)

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 other is null, the current instance is returned.
  • If other is an int, it is interpreted as milliseconds and is added to the current instance.
  • If other is a Time or Duration instance, its added to the current instance.

Throws:

  • A StateError if other is not null, Time, int, or Duration.

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");
}