parse function

Duration parse (String durationString)

Implementation

Duration parse(String durationString) {
  Match match = _regex.firstMatch(durationString);
  final result = {};
  for (int i = 1; i <= match.groupCount; i++) {
    result[_objMap[i - 1]] = _getNum(match.group(i));
  }

  if (result['weeks'] > 0) {
    num days = result['weeks'] * 7;
    return new Duration(days: days);
  }

  num days = (result['years'] * 365) + (result['months'] * 30) + result['days'];
  num hours = result['hours'];
  num minutes = result['minutes'];
  num seconds = result['seconds'];
  return new Duration(
      days: days, hours: hours, minutes: minutes, seconds: seconds);
}