letDateTimeOrNull function

DateTime? letDateTimeOrNull(
  1. dynamic input
)

Let's you convert input to a DateTime type if possible, or returns null if the conversion cannot be performed.

Implementation

DateTime? letDateTimeOrNull(dynamic input) {
  if (input is DateTime) {
    return input;
  }
  if (input is String) {
    return DateTime.tryParse(input);
  }
  return null;
}