1.1 --- a/EventAggregatorSupport.py Tue Mar 24 01:21:36 2009 +0100
1.2 +++ b/EventAggregatorSupport.py Wed Mar 25 00:37:13 2009 +0100
1.3 @@ -136,12 +136,14 @@
1.4
1.5 return date
1.6
1.7 -def daterange(first, last):
1.8 +def daterange(first, last, step=1):
1.9
1.10 - "Get the range of dates starting at 'first' and ending on 'last'."
1.11 + """
1.12 + Get the range of dates starting at 'first' and ending on 'last', using the
1.13 + specified 'step'.
1.14 + """
1.15
1.16 results = []
1.17 - step = last > first and 1 or -1
1.18
1.19 months_only = len(first) == 2
1.20 start_year = first[0]
1.21 @@ -233,6 +235,12 @@
1.22 else:
1.23 return year, month - 1
1.24
1.25 +def span(start, end):
1.26 +
1.27 + "Return the difference between 'start' and 'end'."
1.28 +
1.29 + return end[0] - start[0], end[1] - start[1]
1.30 +
1.31 def getEvents(request, category_names, calendar_start=None, calendar_end=None):
1.32
1.33 """
1.34 @@ -312,4 +320,35 @@
1.35
1.36 return events, shown_events, all_shown_events, earliest, latest
1.37
1.38 +def getConcretePeriod(calendar_start, calendar_end, earliest, latest):
1.39 +
1.40 + """
1.41 + From the requested 'calendar_start' and 'calendar_end', which may be None,
1.42 + indicating that no restriction is imposed on the period for each of the
1.43 + boundaries, use the 'earliest' and 'latest' event months to define a
1.44 + specific period of interest.
1.45 + """
1.46 +
1.47 + # Define the period as starting with any specified start month or the
1.48 + # earliest event known, ending with any specified end month or the latest
1.49 + # event known.
1.50 +
1.51 + first = calendar_start or earliest
1.52 + last = calendar_end or latest
1.53 +
1.54 + # If there is no range of months to show, perhaps because there are no
1.55 + # events in the requested period, and there was no start or end month
1.56 + # specified, show only the month indicated by the start or end of the
1.57 + # requested period. If all events were to be shown but none were found show
1.58 + # the current month.
1.59 +
1.60 + if first is None:
1.61 + first = last or getCurrentMonth()
1.62 + if last is None:
1.63 + last = first or getCurrentMonth()
1.64 +
1.65 + # Permit "expiring" periods (where the start date approaches the end date).
1.66 +
1.67 + return min(first, last), last
1.68 +
1.69 # vim: tabstop=4 expandtab shiftwidth=4