Commits

Brandon Nielsen committed cad4717

Fix issue #1 for Python3.

Comments (0)

Files changed (2)

python3/aniso8601/duration.py

         raise ValueError('String is not a valid ISO8601 duration.')
 
     #If Y, M, D, H, or S are in the string, assume it is a specified duration
-    if isodurationstr.find('Y') != -1 or isodurationstr.find('M') != -1 or isodurationstr.find('D') != -1 or isodurationstr.find('H') != -1 or isodurationstr.find('S') != -1:
+    if isodurationstr.find('Y') != -1 or isodurationstr.find('M') != -1 or isodurationstr.find('W') != -1 or isodurationstr.find('D') != -1 or isodurationstr.find('H') != -1 or isodurationstr.find('S') != -1:
         return parse_duration_prescribed(isodurationstr)
     else:
         return parse_duration_combined(isodurationstr)
         else:
             months = 0
 
+        if durationstr.find('W') != -1:
+            weeks = _parse_duration_element(durationstr, 'W')
+        else:
+            weeks = 0
+
         if durationstr.find('D') != -1:
             days = _parse_duration_element(durationstr, 'D')
         else:
         else:
             months = 0
 
+        if durationstr.find('W') != -1:
+            weeks = _parse_duration_element(durationstr, 'W')
+        else:
+            weeks = 0
+
         if firsthalf.find('D') != -1:
             days = _parse_duration_element(firsthalf, 'D')
         else:
         else:
             seconds = 0
 
-    totaldays = years * 365 + months * 30 + days
+    totaldays = years * 365 + months * 30 + weeks * 7 + days
 
     return datetime.timedelta(days=totaldays, hours=hours, minutes=minutes, seconds=seconds)
 

python3/aniso8601/tests/test_duration.py

         resultduration = parse_duration('P1M')
         self.assertEqual(resultduration.days, 30)
 
+        resultduration = parse_duration('P1W')
+        self.assertEqual(resultduration.days, 7)
+
+        resultduration = parse_duration('P1D')
+        self.assertEqual(resultduration.days, 1)
+
         resultduration = parse_duration('P0003-06-04T12:30:05')
         self.assertEqual(resultduration.days, 1279)
         self.assertEqual(resultduration.seconds, 45005)
         resultduration = parse_duration_prescribed('P1M')
         self.assertEqual(resultduration.days, 30)
 
+        resultduration = parse_duration_prescribed('P1W')
+        self.assertEqual(resultduration.days, 7)
+
+        resultduration = parse_duration_prescribed('P1D')
+        self.assertEqual(resultduration.days, 1)
+
     def test_parse_duration_combined(self):
         resultduration = parse_duration_combined('P0003-06-04T12:30:05')
         self.assertEqual(resultduration.days, 1279)