isBefore method
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? date]) {
DateTime referenceDate;
if (date == null) {
referenceDate = DateTime.now();
} else if (date.isDate) {
referenceDate = DateTime.parse(date);
} else {
return false;
}
final strDate = DateTime.tryParse(this);
if (strDate == null) return false;
return strDate.isBefore(referenceDate);
}