1.1 --- a/vRecurrence.py Sun Oct 22 01:24:08 2017 +0200
1.2 +++ b/vRecurrence.py Sun Oct 22 17:02:40 2017 +0200
1.3 @@ -645,6 +645,16 @@
1.4 l.sort(cmp=fn)
1.5 return l
1.6
1.7 +def convert_positions(setpos):
1.8 +
1.9 + "Convert 'setpos' to 0-based indexes."
1.10 +
1.11 + l = []
1.12 + for pos in setpos:
1.13 + index = pos < 0 and pos or pos - 1
1.14 + l.append(index)
1.15 + return l
1.16 +
1.17 # Classes for producing instances from recurrence structures.
1.18
1.19 class Selector:
1.20 @@ -702,28 +712,15 @@
1.21 if self.selecting:
1.22 return self.selecting.materialise_items(current, earliest, next,
1.23 counter, setpos, inclusive)
1.24 - elif earliest <= current:
1.25 + else:
1.26 return [current]
1.27 - else:
1.28 - return []
1.29 -
1.30 - def convert_positions(self, setpos):
1.31 -
1.32 - "Convert 'setpos' to 0-based indexes."
1.33 -
1.34 - l = []
1.35 - for pos in setpos:
1.36 - index = pos < 0 and pos or pos - 1
1.37 - l.append(index)
1.38 - return l
1.39
1.40 def select_positions(self, results, setpos):
1.41
1.42 "Select in 'results' the 1-based positions given by 'setpos'."
1.43
1.44 - results.sort()
1.45 l = []
1.46 - for index in self.convert_positions(setpos):
1.47 + for index in convert_positions(setpos):
1.48 l.append(results[index])
1.49 return l
1.50
1.51 @@ -851,7 +848,7 @@
1.52 # Find each of the given days.
1.53
1.54 for value, index in sort_weekdays(self.args["values"], first_day, last_day):
1.55 - offset = timedelta(7 * (abs(index) - 1))
1.56 + offset = timedelta(7 * (index - 1))
1.57
1.58 current = precision(to_tuple(get_first_day(first_day, value) + offset), DAYS)
1.59 next = update(current, step)