isDateInFuture function

IValidator isDateInFuture({
  1. bool allowNow = true,
  2. String? message,
})

DateTime must be in the future.

Implementation

IValidator isDateInFuture({bool allowNow = true, String? message}) {
  final now = DateTime.now();

  return _datePredicate(
    defaultMessage: 'a DateTime in the future${allowNow ? ' or now' : ''}',
    test: (v) => allowNow ? !v.isBefore(now) : v.isAfter(now),
    code: ExpectationCodes.valueDateNotFuture,
    dataBuilder: () => {'now': now.toIso8601String(), 'allowNow': allowNow},
    message: message,
  );
}