1.1 --- a/EventAggregatorSupport.py Sun Feb 06 02:49:57 2011 +0100
1.2 +++ b/EventAggregatorSupport.py Sun Feb 06 19:48:43 2011 +0100
1.3 @@ -979,12 +979,13 @@
1.4
1.5 if isinstance(start, DateTime):
1.6 times.add(start)
1.7 + else:
1.8 + times.add(start.as_datetime(None, None, None, None))
1.9
1.10 if isinstance(end, DateTime):
1.11 - if end.has_time():
1.12 - times.add(end)
1.13 - else:
1.14 - times.add(end.as_date().next_day())
1.15 + times.add(end)
1.16 + else:
1.17 + times.add(end.as_date().next_day())
1.18
1.19 times = list(times)
1.20 times.sort(cmp_dates_as_day_start)
1.21 @@ -1087,6 +1088,12 @@
1.22 units.append(current)
1.23 return units
1.24
1.25 + def ambiguous(self):
1.26 +
1.27 + "Only times can be ambiguous."
1.28 +
1.29 + return 0
1.30 +
1.31 class Month(Temporal):
1.32
1.33 "A simple year-month representation."
1.34 @@ -1288,19 +1295,29 @@
1.35 compares their raw time data.
1.36 """
1.37
1.38 - this = self.as_datetime_or_date()
1.39 -
1.40 - if isinstance(this, DateTime) and isinstance(other, DateTime):
1.41 - other = other.as_datetime_or_date()
1.42 + this = self
1.43 +
1.44 + if this.has_time():
1.45 if isinstance(other, DateTime):
1.46 - this_utc = this.to_utc()
1.47 - other_utc = other.to_utc()
1.48 - if this_utc is not None and other_utc is not None:
1.49 - return cmp(this_utc.as_tuple(), other_utc.as_tuple())
1.50 + if other.has_time():
1.51 + this_utc = this.to_utc()
1.52 + other_utc = other.to_utc()
1.53 + if this_utc is not None and other_utc is not None:
1.54 + return cmp(this_utc.as_tuple(), other_utc.as_tuple())
1.55 + else:
1.56 + other = other.padded()
1.57 + else:
1.58 + this = this.padded()
1.59
1.60 return Date.__cmp__(this, other)
1.61
1.62 def has_time(self):
1.63 +
1.64 + """
1.65 + Return whether this object has any time information. Objects without
1.66 + time information can refer to the very start of a day.
1.67 + """
1.68 +
1.69 return self.data[3] is not None and self.data[4] is not None
1.70
1.71 def time(self):
1.72 @@ -1315,11 +1332,21 @@
1.73 def set_time_zone(self, value):
1.74 self.data[6] = value
1.75
1.76 - def padded(self):
1.77 -
1.78 - "Return a datetime with missing fields defined as being zero."
1.79 -
1.80 - data = map(lambda x: x or 0, self.data[:6]) + self.data[6:]
1.81 + def padded(self, empty_value=0):
1.82 +
1.83 + """
1.84 + Return a datetime with missing fields defined as being the given
1.85 + 'empty_value' or 0 if not specified.
1.86 + """
1.87 +
1.88 + data = []
1.89 + for x in self.data[:6]:
1.90 + if x is None:
1.91 + data.append(empty_value)
1.92 + else:
1.93 + data.append(x)
1.94 +
1.95 + data += self.data[6:]
1.96 return DateTime(data)
1.97
1.98 def to_utc(self):
1.99 @@ -1520,7 +1547,10 @@
1.100 comparisons.
1.101 """
1.102
1.103 - if isinstance(a, DateTime) and a.has_time() and isinstance(b, DateTime) and b.has_time():
1.104 + # Datetimes without times can be equal to dates and be considered as
1.105 + # occurring before those dates.
1.106 +
1.107 + if isinstance(a, DateTime) and (isinstance(b, DateTime) or not a.has_time()):
1.108 return a <= b
1.109 else:
1.110 return a < b
1.111 @@ -1554,13 +1584,10 @@
1.112 else:
1.113 return 0
1.114
1.115 - # Points in time are not considered to represent an upper bound on a
1.116 - # non-inclusive timespan.
1.117 -
1.118 else:
1.119 if self.end is not None and self.is_before(self.end, other):
1.120 return -1
1.121 - elif self.start is not None and self.start > other:
1.122 + elif self.start is not None and self.is_before(other, self.start):
1.123 return 1
1.124 else:
1.125 return 0
1.126 @@ -1644,7 +1671,11 @@
1.127
1.128 def getDateTime(s):
1.129
1.130 - "Parse the string 's', extracting and returning a datetime object."
1.131 + """
1.132 + Parse the string 's', extracting and returning a datetime object where time
1.133 + information has been given or a date object where time information is
1.134 + absent.
1.135 + """
1.136
1.137 m = datetime_regexp.search(s)
1.138 if m:
1.139 @@ -1652,7 +1683,7 @@
1.140
1.141 # Convert date and time data to integer or None.
1.142
1.143 - return DateTime(map(int_or_none, groups[:6]) + [m.group("zone")])
1.144 + return DateTime(map(int_or_none, groups[:6]) + [m.group("zone")]).as_datetime_or_date()
1.145 else:
1.146 return None
1.147