@@ -81,8 +81,9 @@ def parse_duration(duration):
81
81
assert duration [index ] == "P"
82
82
index += 1
83
83
84
- dic = dict ([(typ , 0 ) for (code , typ ) in D_FORMAT ])
85
-
84
+ dic = dict ([(typ , 0 ) for (code , typ ) in D_FORMAT if typ ])
85
+ dlen = len (duration )
86
+
86
87
for code , typ in D_FORMAT :
87
88
#print duration[index:], code
88
89
if duration [index ] == '-' :
@@ -99,22 +100,31 @@ def parse_duration(duration):
99
100
else :
100
101
try :
101
102
mod = duration [index :].index (code )
103
+ _val = duration [index :index + mod ]
102
104
try :
103
- dic [typ ] = int (duration [ index : index + mod ] )
105
+ dic [typ ] = int (_val )
104
106
except ValueError :
105
- if code == "S" :
107
+ # smallest value used may also have a decimal fraction
108
+ if mod + index + 1 == dlen :
106
109
try :
107
- dic [typ ] = float (duration [ index : index + mod ] )
110
+ dic [typ ] = float (_val )
108
111
except ValueError :
109
- raise Exception ("Not a float" )
112
+ if "," in _val :
113
+ _val = _val .replace ("," , "." )
114
+ try :
115
+ dic [typ ] = float (_val )
116
+ except ValueError :
117
+ raise Exception ("Not a float" )
118
+ else :
119
+ raise Exception ("Not a float" )
110
120
else :
111
- raise Exception (
112
- "Fractions not allow on anything byt seconds " )
121
+ raise ValueError (
122
+ "Fraction not allowed on other than smallest value " )
113
123
index = mod + index + 1
114
124
except ValueError :
115
125
dic [typ ] = 0
116
126
117
- if index == len ( duration ) :
127
+ if index == dlen :
118
128
break
119
129
120
130
return sign , dic
0 commit comments