validDateTimeRange static method

bool validDateTimeRange({
  1. required String fromDateTime,
  2. required String toDateTime,
  3. String format = Format.fyyyyMMdd,
  4. bool considerSameDateTime = true,
})

check valid date range or not

Implementation

static bool validDateTimeRange(
    {required String fromDateTime,
    required String toDateTime,
    String format = Format.fyyyyMMdd,
    bool considerSameDateTime = true}) {
  if (considerSameDateTime) {
    return stringToDateTime(date: fromDateTime, format: format)
            .isBefore(stringToDateTime(date: toDateTime, format: format)) ||
        stringToDateTime(date: fromDateTime, format: format).isAtSameMomentAs(
            stringToDateTime(date: toDateTime, format: format));
  } else {
    return stringToDateTime(date: fromDateTime, format: format)
        .isBefore(stringToDateTime(date: toDateTime, format: format));
  }
}