code: def parse_duration(line):
      
      DAYS, SECS = {'D': 1, 'W': 7}, {'S': 1, 'M': 60, 'H': 3600}
      sign, i = 1, 0
      if line[i] in '-+':
          if line[i] == '-':
              sign = -1
          i += 1
      if line[i] != 'P':
          raise parse.ParseError()
      i += 1
      days, secs = 0, 0
      while i < len(line):
          if line[i] == 'T':
              i += 1
              if i == len(line):
                  break
          j = i
          while line[j].isdigit():
              j += 1
          if i == j:
              raise parse.ParseError()
          val = int(line[i:j])
          if line[j] in DAYS:
              days += val * DAYS[line[j]]
              DAYS.pop(line[j])
          elif line[j] in SECS:
              secs += val * SECS[line[j]]
              SECS.pop(line[j])
          else:
              raise parse.ParseError()
          i = j + 1
      return timedelta(sign * days, sign * secs)
docs: Return a timedelta object from a string in the DURATION property format