operator == method

  1. @override
bool operator ==(
  1. Object other
)
override

Overrides the equality operator to compare the current DateRange object with another object. Returns true if the objects are equal, false otherwise. Checks if the current DateRange object is equal to the other object.

The equality comparison is performed based on the type of the other object. If other is of type DateRange, the comparison is based on the hash codes of the two objects. If other is of type int, the comparison is based on the milliseconds of the duration property. If other is of type Duration, the comparison is based on the equality of the duration property. If other is of type date, the comparison is based on whether the other date is contained within the DateRange. If other is of type List<date>, the comparison is based on whether the minimum date of the other list is equal to the startDate and the maximum date of the other list is equal to the endDate. If other is of type (date, date), the comparison is based on whether the minimum date of the tuple is equal to the startDate and the maximum date of the tuple is equal to the endDate. If other is of type string, the comparison is based on the type of the other string. If the other string is a valid date, the comparison is based on whether the date is contained within the DateRange. If the other string is a valid number, the comparison is based on whether the milliseconds of the duration property is equal to the number. Other types return false. Returns true if the objects are equal, false otherwise.

Implementation

@override
bool operator ==(Object other) {
  if (other is DateRange) {
    return hashCode == other.hashCode;
  }
  if (other is int) {
    return inMilliseconds == other;
  }
  if (other is Duration) {
    return duration == other;
  }
  if (other is date) {
    return contains(other);
  }

  if (other is Iterable<date>) {
    return other.min == startDate && other.max == endDate;
  }

  if (other is (date, date)) {
    var t = other.$1.compareAndSwap(other.$2);
    return t.min == startDate && t.max == endDate;
  }

  if (other is string) {
    if (other.isDate) {
      return contains(other.toDate());
    }
    if (other.isNumber) {
      return inMilliseconds == other.toInt!;
    }
  }
  return false;
}