1.1 --- a/vRecurrence.py Tue Feb 10 21:53:52 2015 +0100
1.2 +++ b/vRecurrence.py Tue Feb 10 23:41:02 2015 +0100
1.3 @@ -284,9 +284,21 @@
1.4 # Datetime arithmetic.
1.5
1.6 def combine(t1, t2):
1.7 +
1.8 + """
1.9 + Combine tuples 't1' and 't2', returning a copy of 't1' filled with values
1.10 + from 't2' in positions where 0 appeared in 't1'.
1.11 + """
1.12 +
1.13 return tuple(map(lambda x, y: x or y, t1, t2))
1.14
1.15 def scale(interval, pos):
1.16 +
1.17 + """
1.18 + Scale the given 'interval' value to the indicated position 'pos', returning
1.19 + a tuple with leading zero elements and 'interval' at the stated position.
1.20 + """
1.21 +
1.22 return (0,) * pos + (interval,)
1.23
1.24 def get_seconds(t):
1.25 @@ -333,6 +345,9 @@
1.26 return to_tuple(d + s, len(t))
1.27
1.28 def to_tuple(d, n=None):
1.29 +
1.30 + "Return 'd' as a tuple, optionally trimming the result to 'n' positions."
1.31 +
1.32 if not isinstance(d, date):
1.33 return d
1.34 if n is None:
1.35 @@ -343,6 +358,9 @@
1.36 return d.timetuple()[:n]
1.37
1.38 def get_first_day(first_day, weekday):
1.39 +
1.40 + "Return the first occurrence at or after 'first_day' of 'weekday'."
1.41 +
1.42 first_day = date(*first_day)
1.43 first_weekday = first_day.isoweekday()
1.44 if first_weekday > weekday:
1.45 @@ -351,6 +369,9 @@
1.46 return first_day + timedelta(weekday - first_weekday)
1.47
1.48 def get_last_day(last_day, weekday):
1.49 +
1.50 + "Return the last occurrence at or before 'last_day' of 'weekday'."
1.51 +
1.52 last_day = date(*last_day)
1.53 last_weekday = last_day.isoweekday()
1.54 if last_weekday < weekday:
1.55 @@ -599,6 +620,12 @@
1.56 return selectors[0]
1.57
1.58 def get_selector(dt, qualifiers):
1.59 +
1.60 + """
1.61 + Combine the initial datetime 'dt' with the given 'qualifiers', returning an
1.62 + object that can be used to select recurrences described by the 'qualifiers'.
1.63 + """
1.64 +
1.65 dt = to_tuple(dt)
1.66 return connect_selectors(combine_datetime_with_qualifiers(dt, qualifiers))
1.67