isDateTime static method

bool isDateTime(
  1. dynamic v, {
  2. String format = defDateTimeFormat,
  3. String? locale,
  4. bool isUtc = false,
})

Implementation

static bool isDateTime(v,
    {String format = defDateTimeFormat, String? locale, bool isUtc = false}) {
  if (v == null) return true;
  if (v is num) return true;
  if (v is DateTime) return true;
  if (v is String) {
    final num? n = num.tryParse(v);
    if (n != null) return true;

    final df = DateFormat(format, locale);
    try {
      df.parse(v, isUtc);
      return true;
    } catch (e) {
      return false;
    }
  }
  return false;
}