1.1 --- a/EventAggregatorSupport.py Wed Apr 13 00:32:04 2011 +0200
1.2 +++ b/EventAggregatorSupport.py Fri Apr 15 00:14:04 2011 +0200
1.3 @@ -888,7 +888,7 @@
1.4
1.5 return Timespan(calendar_start, calendar_end)
1.6
1.7 -def getConcretePeriod(calendar_start, calendar_end, earliest, latest):
1.8 +def getConcretePeriod(calendar_start, calendar_end, earliest, latest, resolution):
1.9
1.10 """
1.11 From the requested 'calendar_start' and 'calendar_end', which may be None,
1.12 @@ -910,7 +910,7 @@
1.13 # requested period. If all events were to be shown but none were found show
1.14 # the current month.
1.15
1.16 - if isinstance(first, Date):
1.17 + if resolution == "date":
1.18 get_current = getCurrentDate
1.19 else:
1.20 get_current = getCurrentMonth
1.21 @@ -920,6 +920,10 @@
1.22 if last is None:
1.23 last = first or get_current()
1.24
1.25 + if resolution == "month":
1.26 + first = first.as_month()
1.27 + last = last.as_month()
1.28 +
1.29 # Permit "expiring" periods (where the start date approaches the end date).
1.30
1.31 return min(first, last), last
1.32 @@ -1052,7 +1056,7 @@
1.33 def __init__(self, data):
1.34 self.data = data
1.35
1.36 - def months(self):
1.37 + def count(self):
1.38 return self.data[0] * 12 + self.data[1]
1.39
1.40 class Convertible:
1.41 @@ -1106,7 +1110,7 @@
1.42 length = min(len(data), len(other_data))
1.43 return cmp(data[:length], other_data[:length])
1.44
1.45 - def until(self, start, end, nextfn, prevfn):
1.46 + def _until(self, start, end, nextfn, prevfn):
1.47
1.48 """
1.49 Return a collection of units of time by starting from the given 'start'
1.50 @@ -1171,18 +1175,24 @@
1.51 year, month = self.as_tuple()[:2]
1.52 return Month((year + (month - 1 + n) / 12, (month - 1 + n) % 12 + 1))
1.53
1.54 + update = month_update
1.55 +
1.56 def next_month(self):
1.57
1.58 "Return the month following this one."
1.59
1.60 return self.month_update(1)
1.61
1.62 + next = next_month
1.63 +
1.64 def previous_month(self):
1.65
1.66 "Return the month preceding this one."
1.67
1.68 return self.month_update(-1)
1.69
1.70 + previous = previous_month
1.71 +
1.72 def __sub__(self, start):
1.73
1.74 """
1.75 @@ -1196,7 +1206,9 @@
1.76
1.77 "Return the collection of months from this month until 'end'."
1.78
1.79 - return self.until(self.as_month(), end.as_month(), Month.next_month, Month.previous_month)
1.80 + return self._until(self.as_month(), end.as_month(), Month.next_month, Month.previous_month)
1.81 +
1.82 + until = months_until
1.83
1.84 class Date(Month):
1.85
1.86 @@ -1238,6 +1250,8 @@
1.87 dt_new = dt + delta
1.88 return Date((dt_new.year, dt_new.month, dt_new.day))
1.89
1.90 + update = day_update
1.91 +
1.92 def next_day(self):
1.93
1.94 "Return the date following this one."
1.95 @@ -1252,6 +1266,8 @@
1.96 else:
1.97 return Date((year, month, day + 1))
1.98
1.99 + next = next_day
1.100 +
1.101 def previous_day(self):
1.102
1.103 "Return the date preceding this one."
1.104 @@ -1266,11 +1282,15 @@
1.105 else:
1.106 return Date((year, month, day - 1))
1.107
1.108 + previous = previous_day
1.109 +
1.110 def days_until(self, end):
1.111
1.112 "Return the collection of days from this date until 'end'."
1.113
1.114 - return self.until(self.as_date(), end.as_date(), Date.next_day, Date.previous_day)
1.115 + return self._until(self.as_date(), end.as_date(), Date.next_day, Date.previous_day)
1.116 +
1.117 + until = days_until
1.118
1.119 class DateTime(Date):
1.120