--- 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[+-]?)(?P[\d]?)' '(?P[\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