isBefore function

bool isBefore(
  1. String str, [
  2. String? date
])

check if the string is a date that's before the specified date

If date is not passed, it defaults to now.

Implementation

bool isBefore(String str, [String? date]) {
  DateTime referenceDate;
  if (date == null) {
    referenceDate = DateTime.now();
  } else if (isDate(date)) {
    referenceDate = DateTime.parse(date);
  } else {
    return false;
  }

  final strDate = DateTime.tryParse(str);
  if (strDate == null) return false;

  return strDate.isBefore(referenceDate);
}