isBefore method

  1. @override
bool isBefore(
  1. DateTime other
)
override

Whether this DateTime occurs before other.

The comparison is independent of whether the time is in UTC or in the local time zone.

final now = DateTime.now();
final earlier = now.subtract(const Duration(seconds: 5));
print(earlier.isBefore(now)); // true
print(!now.isBefore(now)); // true

// This relation stays the same, even when changing timezones.
print(earlier.isBefore(now.toUtc())); // true
print(earlier.toUtc().isBefore(now)); // true

print(!now.toUtc().isBefore(now)); // true
print(!now.isBefore(now.toUtc())); // true

Implementation

@override
bool isBefore(DateTime other) => $value.isBefore(other);