isDateBefore function

IValidator isDateBefore(
  1. DateTime dt, {
  2. bool inclusive = false,
  3. String? message,
})

DateTime must be before (or equal if inclusive) given bound.

Implementation

IValidator isDateBefore(DateTime dt, {bool inclusive = false, String? message}) {
  return _datePredicate(
    defaultMessage:
        'a DateTime before${inclusive ? ' or equal to' : ''} ${dt.toIso8601String()}',
    test: (v) => inclusive ? !v.isAfter(dt) : v.isBefore(dt),
    code: ExpectationCodes.valueDateOutOfRange,
    dataBuilder: () => {
      'bound': dt.toIso8601String(),
      'op': 'before',
      'inclusive': inclusive,
    },
    message: message,
  );
}