toDateTime method

DateTime? toDateTime({
  1. dynamic context,
})

Parse string to DateTime or Null

Implementation

DateTime? toDateTime({dynamic context}) {
  String value = this;
  DateTime? tempDateTime;
  if (value.isEmpty) {
    errorLogsNS('toDateTime invalid $value context:$context');
    return tempDateTime;
  }
  if (value.startsWith('-00')) {
    errorLogsNS('toDateTime invalid $value context:$context');
    value = value.replaceFirst('-00', '');
  }
  try {
    tempDateTime = DateTime.parse(value);
  } on Exception catch (e, s) {
    errorLogsNS("toDateTime $context  $value ", e, s);
  }
  return tempDateTime;
}