isWithinLast function

bool isWithinLast(
  1. String str,
  2. Duration duration
)

Returns true if str is in the past and no older than duration.

A date in the future returns false.

isWithinLast(signupDate, const Duration(days: 30));

Implementation

bool isWithinLast(String str, Duration duration) {
  final date = tryParseDate(str);
  if (date == null) return false;
  final now = DateTime.now().toUtc();
  return !date.isAfter(now) && date.isAfter(now.subtract(duration));
}