dateValue static method

DateTime? dateValue(
  1. Map<String, dynamic>? info,
  2. String key, [
  3. bool strictType = true
])

Implementation

static DateTime? dateValue(Map<String,dynamic>? info, String key, [bool strictType = true]) {
  if (info == null) { return null; }
  final value = info[key];
  if (value != null && value is DateTime) {
    return value;
  }
  int timestamp = -1;
  final data = info[key];
  if (data is int) {
    timestamp = data;
  } else if (strictType == false) {
    if (data is String) {
      timestamp = int.parse(data);
    }
  }
  if (timestamp > 0) {
    if (timestamp > 9999999999) {
      return DateTime.fromMillisecondsSinceEpoch(timestamp);
    } else {
      return DateTime.fromMillisecondsSinceEpoch((timestamp * 1000));
    }
  } else {
    return null;
  }
}