parseTime static method

int parseTime(
  1. Object? value
)

Parses a clock time into minutes since midnight, without a date/timezone.

Implementation

static int parseTime(Object? value) {
  if (value is! String ||
      value.length != 5 ||
      !RegExp(r'^[0-9]{2}:[0-9]{2}$').hasMatch(value)) {
    throw const FormatException('Expected a time in HH:mm format.');
  }
  final hour = int.parse(value.substring(0, 2));
  final minute = int.parse(value.substring(3, 5));
  if (hour > 23 || minute > 59) {
    throw const FormatException('Expected a valid 24-hour time.');
  }
  return hour * 60 + minute;
}