isDateBetween function

IValidator isDateBetween(
  1. DateTime start,
  2. DateTime end, {
  3. bool inclusiveStart = true,
  4. bool inclusiveEnd = true,
  5. String? message,
})

DateTime must fall within the interval.

Implementation

IValidator isDateBetween(
  DateTime start,
  DateTime end, {
  bool inclusiveStart = true,
  bool inclusiveEnd = true,
  String? message,
}) {
  return _datePredicate(
    defaultMessage:
        'a DateTime between ${start.toIso8601String()} and ${end.toIso8601String()} (${inclusiveStart ? '[' : '('}${inclusiveEnd ? ']' : ')'})',
    test: (v) =>
        (inclusiveStart ? !v.isBefore(start) : v.isAfter(start)) &&
        (inclusiveEnd ? !v.isAfter(end) : v.isBefore(end)),
    code: ExpectationCodes.valueDateOutOfRange,
    dataBuilder: () => {
      'start': start.toIso8601String(),
      'end': end.toIso8601String(),
      'inclusiveStart': inclusiveStart,
      'inclusiveEnd': inclusiveEnd,
    },
    message: message,
  );
}