1.1 --- a/EventAggregatorSupport.py Sun Jan 16 19:30:01 2011 +0100
1.2 +++ b/EventAggregatorSupport.py Mon Jan 17 02:26:17 2011 +0100
1.3 @@ -631,6 +631,9 @@
1.4 self.page = page
1.5 self.details = details
1.6
1.7 + def __hash__(self):
1.8 + return hash(self.getSummary())
1.9 +
1.10 def getPage(self):
1.11
1.12 "Return the page describing this event."
1.13 @@ -701,8 +704,8 @@
1.14 else:
1.15 return None
1.16
1.17 - def as_times(self):
1.18 - return self.as_timespan().as_times()
1.19 + def as_limits(self):
1.20 + return self.as_timespan().as_limits()
1.21
1.22 def getEvents(request, category_names, calendar_start=None, calendar_end=None, resolution="month"):
1.23
1.24 @@ -786,7 +789,7 @@
1.25 # Test for the suitability of the event.
1.26
1.27 if event.as_timespan() is not None:
1.28 - start, end = map(convert, event.as_timespan().as_times())
1.29 + start, end = map(convert, event.as_timespan().as_limits())
1.30
1.31 # Compare the dates to the requested calendar window, if any.
1.32
1.33 @@ -963,9 +966,19 @@
1.34
1.35 times = set()
1.36 for timespan in coverage:
1.37 - start, end = timespan.as_times()
1.38 - times.add(start)
1.39 - times.add(end)
1.40 + start, end = timespan.as_limits()
1.41 +
1.42 + # Add either genuine times or dates converted to times.
1.43 +
1.44 + if isinstance(start, DateTime):
1.45 + times.add(start)
1.46 +
1.47 + if isinstance(end, DateTime):
1.48 + if end.has_time():
1.49 + times.add(end)
1.50 + else:
1.51 + times.add(end.as_date().next_day())
1.52 +
1.53 times = list(times)
1.54 times.sort()
1.55
1.56 @@ -1194,6 +1207,9 @@
1.57 self.data[3:6] = hour, minute, second
1.58
1.59 def __str__(self):
1.60 + return Date.__str__(self) + self.time_string()
1.61 +
1.62 + def time_string(self):
1.63 if self.has_time():
1.64 data = self.as_tuple()
1.65 time_str = " %02d:%02d" % data[3:5]
1.66 @@ -1201,10 +1217,9 @@
1.67 time_str += ":%02d" % data[5]
1.68 if data[6] is not None:
1.69 time_str += " %s" % data[6]
1.70 + return time_str
1.71 else:
1.72 - time_str = ""
1.73 -
1.74 - return Date.__str__(self) + time_str
1.75 + return ""
1.76
1.77 def as_datetime(self):
1.78 return self
1.79 @@ -1212,17 +1227,37 @@
1.80 def as_date(self):
1.81 return Date(self.data[:3])
1.82
1.83 + def as_datetime_or_date(self):
1.84 +
1.85 + """
1.86 + Return a date for this datetime if fields are missing. Otherwise, return
1.87 + this datetime itself.
1.88 + """
1.89 +
1.90 + if not self.has_time():
1.91 + return self.as_date()
1.92 + else:
1.93 + return self
1.94 +
1.95 def __cmp__(self, other):
1.96 - if isinstance(other, DateTime):
1.97 - self_utc = self.to_utc()
1.98 - other_utc = other.to_utc()
1.99 - if self_utc is not None and other_utc is not None:
1.100 - return cmp(self_utc.as_tuple(), other_utc.as_tuple())
1.101 - return Month.__cmp__(self, other)
1.102 + this = self.as_datetime_or_date()
1.103 +
1.104 + if isinstance(this, DateTime) and isinstance(other, DateTime):
1.105 + other = other.as_datetime_or_date()
1.106 + if isinstance(other, DateTime):
1.107 + this_utc = this.to_utc()
1.108 + other_utc = other.to_utc()
1.109 + if this_utc is not None and other_utc is not None:
1.110 + return cmp(this_utc.as_tuple(), other_utc.as_tuple())
1.111 +
1.112 + return Date.__cmp__(this, other)
1.113
1.114 def has_time(self):
1.115 return self.data[3] is not None and self.data[4] is not None
1.116
1.117 + def time(self):
1.118 + return self.data[3:]
1.119 +
1.120 def seconds(self):
1.121 return self.data[5]
1.122
1.123 @@ -1246,6 +1281,9 @@
1.124 defined.
1.125 """
1.126
1.127 + if not self.has_time():
1.128 + return None
1.129 +
1.130 offset = self.utc_offset()
1.131 if offset:
1.132 hours, minutes = offset
1.133 @@ -1256,7 +1294,7 @@
1.134
1.135 # Get the components.
1.136
1.137 - hour, minute, second, zone = self.as_tuple()[3:]
1.138 + hour, minute, second, zone = self.time()
1.139 date = self.as_date()
1.140
1.141 # Add the minutes and hours.
1.142 @@ -1418,17 +1456,17 @@
1.143 def __hash__(self):
1.144 return hash((self.start, self.end))
1.145
1.146 - def as_times(self):
1.147 + def as_limits(self):
1.148 return self.start, self.end
1.149
1.150 def is_before(self, a, b):
1.151 - if isinstance(a, DateTime) and isinstance(b, DateTime):
1.152 + if isinstance(a, DateTime) and a.has_time() and isinstance(b, DateTime) and b.has_time():
1.153 return a <= b
1.154 else:
1.155 return a < b
1.156
1.157 def is_after_or_during(self, a, b):
1.158 - if isinstance(a, DateTime) and isinstance(b, DateTime):
1.159 + if isinstance(a, DateTime) and a.has_time() and isinstance(b, DateTime) and b.has_time():
1.160 return a > b
1.161 else:
1.162 return a >= b
1.163 @@ -1482,7 +1520,7 @@
1.164 value = value.as_timespan()
1.165
1.166 if isinstance(value, Timespan):
1.167 - start, end = map(self.convert_time, value.as_times())
1.168 + start, end = map(self.convert_time, value.as_limits())
1.169 return Timespan(start, end)
1.170 else:
1.171 return self.convert_time(value)
1.172 @@ -1634,7 +1672,10 @@
1.173
1.174 n = None
1.175
1.176 - if arg.startswith("current"):
1.177 + if arg is None:
1.178 + return None
1.179 +
1.180 + elif arg.startswith("current"):
1.181 date = getCurrentDate()
1.182 if len(arg) > 8:
1.183 n = int(arg[7:])
1.184 @@ -1663,7 +1704,10 @@
1.185
1.186 n = None
1.187
1.188 - if arg.startswith("current"):
1.189 + if arg is None:
1.190 + return None
1.191 +
1.192 + elif arg.startswith("current"):
1.193 date = getCurrentMonth()
1.194 if len(arg) > 8:
1.195 n = int(arg[7:])
1.196 @@ -1694,10 +1738,7 @@
1.197 """
1.198
1.199 arg = getQualifiedParameter(request, calendar_name, argname)
1.200 - if arg is not None:
1.201 - return getParameterDate(arg)
1.202 - else:
1.203 - return None
1.204 + return getParameterDate(arg)
1.205
1.206 def getFormMonth(request, calendar_name, argname):
1.207
1.208 @@ -1707,10 +1748,7 @@
1.209 """
1.210
1.211 arg = getQualifiedParameter(request, calendar_name, argname)
1.212 - if arg is not None:
1.213 - return getParameterMonth(arg)
1.214 - else:
1.215 - return None
1.216 + return getParameterMonth(arg)
1.217
1.218 def getFormDateTriple(request, yeararg, montharg, dayarg):
1.219
1.220 @@ -1750,6 +1788,9 @@
1.221 'year_month'.
1.222 """
1.223
1.224 + if not date:
1.225 + return ""
1.226 +
1.227 _ = request.getText
1.228 year, month, day = date.as_tuple()[:3]
1.229 start_weekday, number_of_days = date.month_properties()
1.230 @@ -1765,6 +1806,9 @@
1.231 'year_month'.
1.232 """
1.233
1.234 + if not year_month:
1.235 + return ""
1.236 +
1.237 _ = request.getText
1.238 year, month = year_month.as_tuple()[:2]
1.239 month_label = _(getMonthLabel(month))