parseDuration static method

int? parseDuration(
  1. String? time
)

Implementation

static int? parseDuration(String? time) {
  final regex = RegExp(r'\((\d{1,2}:\d{2})\)');
  final match = regex.firstMatch(time ?? '00:00');
  if (time == null || match == null) return null;

  final extractedTime = match.group(1)!;

  final parts = extractedTime.split(":").reversed.map(int.parse).toList();
  final seconds = parts[0];
  final minutes = parts[1];
  late final int hours;

  if (parts.length > 2) {
    hours = parts[2];
  } else {
    hours = 0;
  }

  return seconds + minutes * 60 + hours * 60 * 60;
}