parseTime function

DateTime parseTime(
  1. String value
)

Implementation

DateTime parseTime(String value) {
  if (value.isEmpty) {
    throw "Empty string";
  }
  if (!RegExp(r"^\d{1,2}:\d{1,2}$").hasMatch(value)) {
    throw "Invalid time format. Must be hh:mm";
  }

  var tokens = value.split(":");
  return DateTime(int.parse(tokens[0]), int.parse(tokens[1]));
}