parseDate function

DateTime? parseDate(
  1. String value
)

Makes a best effort to parse different date time formats. The returned DateTime will be in UTC

Implementation

DateTime? parseDate(String value) {
  try {
    final d = DateTime.parse(value);
    return DateTime.utc(d.year, d.month, d.day, d.hour, d.minute, d.second);
  } on FormatException {
    // noop
  }

  for (final p in parseInfo) {
    if (p.rgx.hasMatch(value)) {
      try {
        return (p.cb != null) ? p.cb!(value.trim(), p) : defaultParser(value.trim(), p);
      } on FormatException {
        // ignore: avoid_print
        print('(regular) format error: [$value] with [${p.format}]');
        rethrow;
      }
    }
  }

  return null;
}