inRange method

  1. @useResult
bool inRange(
  1. DateTime date, {
  2. bool isInclusive = true,
})

Returns true if the given date is within this range.

By default, this check is isInclusive, meaning dates exactly equal to the range's start or end are considered within the range.

Example:

final range = DateTimeRange(
  start: DateTime(2024, 1, 1),
  end: DateTime(2024, 12, 31),
);
range.inRange(DateTime(2024, 6, 15)); // true
range.inRange(DateTime(2024, 1, 1)); // true (inclusive by default)
range.inRange(DateTime(2024, 1, 1), isInclusive: false); // false

Implementation

@useResult
bool inRange(DateTime date, {bool isInclusive = true}) =>
    date.isBetween(start, end, isInclusive: isInclusive);