TimeSpan.ofISOString constructor

TimeSpan.ofISOString(
  1. String isoString
)

Implementation

factory TimeSpan.ofISOString(String isoString) {
  if (isoString.isNotEmpty != true) return TimeSpan.zero;
  final match = durationRegex.firstMatch(isoString);
  if (match == null) return TimeSpan.zero;
  final parts = _newTimeSpanList();
  final bool negated = "-" == match.group(1);

  for (var g = 2; g < 9; g++) {
    final matchGroup = match.group(g);
    if (matchGroup == null) continue;
    parts[g - 2] = matchGroup.toDoubleOrNull() ??
        (throw Exception("Unable to parse $matchGroup"));
  }

  return TimeSpan.ofParts(parts, negated: negated);
}