def parse_duration(duration):
    # (-)PnYnMnDTnHnMnS
    index = 0
    if duration[0] == '-':
        sign = '-'
        index += 1
    else:
        sign = '+'
    assert duration[index] == "P"
    index += 1

    dic = dict([(typ, 0) for (code, typ) in D_FORMAT])

    for code, typ in D_FORMAT:
        # print duration[index:], code
        if duration[index] == '-':
            raise TimeUtilError("Negation not allowed on individual items")
        if code == "T":
            if duration[index] == "T":
                index += 1
                if index == len(duration):
                    raise TimeUtilError("Not allowed to end with 'T'")
            else:
                raise TimeUtilError("Missing T")
        else:
            try:
                mod = duration[index:].index(code)
                try:
                    dic[typ] = int(duration[index:index + mod])
                except ValueError:
                    if code == "S":
                        try:
                            dic[typ] = float(duration[index:index + mod])
                        except ValueError:
                            raise TimeUtilError("Not a float")
                    else:
                        raise TimeUtilError(
                                "Fractions not allow on anything byt seconds")
                index = mod + index + 1
            except __HOLE__:
                dic[typ] = 0

        if index == len(duration):
            break

    return sign, dic
dataset/ETHPy150Open rohe/pyoidc/src/oic/utils/time_util.py/parse_duration