1.1 --- a/vRecurrence.py Mon Dec 04 22:35:42 2017 +0100
1.2 +++ b/vRecurrence.py Mon Dec 04 23:47:37 2017 +0100
1.3 @@ -221,13 +221,20 @@
1.4 # Accept interval indicators for frequency qualifier parameterisation.
1.5
1.6 elif key == "INTERVAL":
1.7 - interval = int(value)
1.8 + interval = max(1, int(value))
1.9 continue
1.10
1.11 # Accept result set selection, truncation and enumerators as qualifiers.
1.12
1.13 elif key in ("BYSETPOS", "COUNT") or enum.has_key(key):
1.14 - qualifier = (key, {"values" : get_qualifier_values(key, value)})
1.15 + values = get_qualifier_values(key, value)
1.16 +
1.17 + # Ignore bad qualifier values.
1.18 +
1.19 + if not values:
1.20 + continue
1.21 +
1.22 + qualifier = (key, {"values" : values})
1.23
1.24 # Ignore other items.
1.25
1.26 @@ -250,31 +257,50 @@
1.27 suitable values.
1.28 """
1.29
1.30 - # For non-weekday selection, obtain a list of numbers.
1.31 -
1.32 - if qualifier != "BYDAY":
1.33 - return map(int, value.split(","))
1.34 -
1.35 - # For weekday selection, obtain the weekday number and instance number.
1.36 -
1.37 values = []
1.38
1.39 - for part in value.split(","):
1.40 - index, weekday = part[:-2], part[-2:]
1.41 + for v in value.split(","):
1.42 + try:
1.43 + # For non-weekday selection, obtain a list of numbers, each in a tuple.
1.44
1.45 - weekday_number = weekdays.get(weekday)
1.46 - if not weekday_number:
1.47 - continue
1.48 + if qualifier != "BYDAY":
1.49 + to_check = (int(v),)
1.50 +
1.51 + # For weekday selection, obtain a list of tuples containing the weekday
1.52 + # and instance number.
1.53 +
1.54 + else:
1.55 + # Split the two-letter weekday code from the preceding text.
1.56
1.57 - if index:
1.58 - index = int(index)
1.59 - else:
1.60 - index = None
1.61 + index, weekday = v[:-2], v[-2:]
1.62 + to_check = (weekday, int_or_empty(index))
1.63 +
1.64 + except ValueError:
1.65 + return None
1.66 +
1.67 + checked = check_values(qualifier, to_check)
1.68
1.69 - values.append((weekday_number, index))
1.70 + # Get single values for non-weekday details.
1.71 +
1.72 + if qualifier != "BYDAY":
1.73 + checked = checked[0]
1.74 +
1.75 + if not checked:
1.76 + return None
1.77 +
1.78 + values.append(checked)
1.79
1.80 return values
1.81
1.82 +def int_or_empty(value):
1.83 +
1.84 + "Return 'value' as an integer or None if null. Raises ValueError."
1.85 +
1.86 + if value:
1.87 + return int(value)
1.88 + else:
1.89 + return None
1.90 +
1.91 def make_selectors(qualifiers):
1.92
1.93 """