isNowInRange method

bool isNowInRange({
  1. DateTime? now,
  2. bool inclusive = true,
})

Checks if the current date and time is within the range.

By default, this check is inclusive, meaning if now equals the start or end of the range, it is considered within the range.

NOTE: You can't really make date optional, even if looking for now, because of microsecond precision. So just cache DateTime.now() and pass it in for consistent results.

Args: now (DateTime?): The date/time to check. Defaults to DateTime.now(). inclusive (bool): If true (default), boundary dates are included.

Returns: bool: true if the date/time is within the range, false otherwise.

Implementation

bool isNowInRange({DateTime? now, bool inclusive = true}) {
  now ??= DateTime.now();

  return inRange(now, inclusive: inclusive);
}