1.1 --- a/EventAggregatorSupport.py Tue Jan 18 00:15:53 2011 +0100
1.2 +++ b/EventAggregatorSupport.py Tue Jan 18 01:48:12 2011 +0100
1.3 @@ -623,7 +623,10 @@
1.4
1.5 return linkToPage(request, self.page, text, query_string)
1.6
1.7 -class Event:
1.8 +class ActsAsTimespan:
1.9 + pass
1.10 +
1.11 +class Event(ActsAsTimespan):
1.12
1.13 "A description of an event."
1.14
1.15 @@ -940,9 +943,8 @@
1.16
1.17 for slot_events in slot:
1.18
1.19 - # Where the event does not overlap with the current
1.20 - # element, add it alongside existing events.
1.21 - # NOTE: Need to use the resolution when testing for overlaps.
1.22 + # Where the event does not overlap with the events in the
1.23 + # current collection, add it alongside these events.
1.24
1.25 if not event in slot_events:
1.26 slot_events.insert_in_order(event)
1.27 @@ -1148,6 +1150,9 @@
1.28 def as_date(self):
1.29 return self
1.30
1.31 + def as_datetime_or_date(self):
1.32 + return self
1.33 +
1.34 def as_month(self):
1.35 return Month(self.data[:2])
1.36
1.37 @@ -1458,7 +1463,7 @@
1.38
1.39 return 0
1.40
1.41 -class Timespan:
1.42 +class Timespan(ActsAsTimespan):
1.43
1.44 """
1.45 A period of time which can be compared against others to check for overlaps.
1.46 @@ -1474,6 +1479,9 @@
1.47 def __hash__(self):
1.48 return hash((self.start, self.end))
1.49
1.50 + def as_timespan(self):
1.51 + return self
1.52 +
1.53 def as_limits(self):
1.54 return self.start, self.end
1.55
1.56 @@ -1511,7 +1519,9 @@
1.57 if their start points follow the other's end point.
1.58 """
1.59
1.60 - if isinstance(other, Timespan):
1.61 + if isinstance(other, ActsAsTimespan):
1.62 + other = other.as_timespan()
1.63 +
1.64 if self.end is not None and other.start is not None and self.is_before(self.end, other.start):
1.65 return -1
1.66 elif self.start is not None and other.end is not None and self.is_before(other.end, self.start):
1.67 @@ -1533,8 +1543,8 @@
1.68 class TimespanCollection:
1.69
1.70 """
1.71 - A collection of timespans with a particular resolution, providing list-like
1.72 - instances which can maintain a coherent ordering of their timespan elements.
1.73 + A collection of timespans providing a list-like interface supporting
1.74 + membership tests at a particular resolution.
1.75 """
1.76
1.77 def __init__(self, resolution, values=None):
1.78 @@ -1543,16 +1553,16 @@
1.79
1.80 if resolution == "date":
1.81 self.convert_time = lambda x: x.as_date()
1.82 + elif resolution == "datetime":
1.83 + self.convert_time = lambda x: x.as_datetime_or_date()
1.84 else:
1.85 self.convert_time = lambda x: x
1.86
1.87 self.values = values or []
1.88
1.89 def convert(self, value):
1.90 - if isinstance(value, Event):
1.91 + if isinstance(value, ActsAsTimespan):
1.92 value = value.as_timespan()
1.93 -
1.94 - if isinstance(value, Timespan):
1.95 start, end = map(self.convert_time, value.as_limits())
1.96 return Timespan(start, end)
1.97 else: