isBetweenRange method
Checks if the current DateTime is within the specified range.
This method delegates to isBetween with the range's start and end dates,
properly forwarding the inclusive parameter to control boundary behavior.
Args:
range (DateTimeRange?): The range to check against. Returns false if null.
inclusive (bool): If true (default), the start and end dates of the range
are included in the check (closed interval). If false, only dates strictly
between start and end are considered in range (open interval).
Returns:
bool: true if the DateTime is within the range according to the
inclusive setting, false otherwise.
Example:
final date = DateTime(2024, 6, 15);
final range = DateTimeRange(
start: DateTime(2024, 6, 1),
end: DateTime(2024, 6, 30),
);
date.isBetweenRange(range); // true
DateTime(2024, 6, 1).isBetweenRange(range, inclusive: true); // true
DateTime(2024, 6, 1).isBetweenRange(range, inclusive: false); // false
Implementation
bool isBetweenRange(DateTimeRange? range, {bool inclusive = true}) {
if (range == null) {
return false;
}
return isBetween(range.start, range.end, inclusive: inclusive);
}