summaryrefslogtreecommitdiff
path: root/dev-python/icalendar/files/2.1_p20100409/03_all_duration-fix.patch
blob: d6d857a342d19ae8767bdb79743c159ba43e1b11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
--- src/icalendar/prop.py.old	Mon Dec 14 13:43:50 2009
+++ src/icalendar/prop.py	Tue Jan 19 15:09:58 2010
@@ -57,7 +57,7 @@
 TIME_PART = r'T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?'
 DATETIME_PART = '(?:%s)?(?:%s)?' % (DATE_PART, TIME_PART)
 WEEKS_PART = r'(\d+)W'
-DURATION_REGEX = re.compile(r'([-+]?)P(?:%s|%s)$'
+DURATION_REGEX = re.compile(r'([-+]?)P(?:%s)?(?:%s)?$'
                             % (WEEKS_PART, DATETIME_PART))
 WEEKDAY_RULE = re.compile('(?P<signal>[+-]?)(?P<relative>[\d]?)'
                           '(?P<weekday>[\w]{2})$')
@@ -467,14 +467,14 @@
         """
         try:
             match = DURATION_REGEX.match(ical)
+            if not any(match.groups()):
+                raise ValueError()
             sign, weeks, days, hours, minutes, seconds = match.groups()
-            if weeks:
-                value = timedelta(weeks=int(weeks))
-            else:
-                value = timedelta(days=int(days or 0),
-                                  hours=int(hours or 0),
-                                  minutes=int(minutes or 0),
-                                  seconds=int(seconds or 0))
+            value = timedelta(weeks=int(weeks or 0),
+                              days=int(days or 0),
+                              hours=int(hours or 0),
+                              minutes=int(minutes or 0),
+                              seconds=int(seconds or 0))
             if sign == '-':
                 value = -value
             return value