1.1 --- a/EventAggregatorSupport.py Mon Mar 29 02:05:45 2010 +0200
1.2 +++ b/EventAggregatorSupport.py Tue Mar 30 20:12:51 2010 +0200
1.3 @@ -808,6 +808,26 @@
1.4 length = min(len(data), len(other_data))
1.5 return cmp(self.data[:length], other.data[:length])
1.6
1.7 + def until(self, start, end, nextfn, prevfn):
1.8 +
1.9 + """
1.10 + Return a collection of units of time by starting from the given 'start'
1.11 + and stepping across intervening units until 'end' is reached, using the
1.12 + given 'nextfn' and 'prevfn' to step from one unit to the next.
1.13 + """
1.14 +
1.15 + current = start
1.16 + units = [current]
1.17 + if current < end:
1.18 + while current < end:
1.19 + current = nextfn(current)
1.20 + units.append(current)
1.21 + elif current > end:
1.22 + while current > end:
1.23 + current = prevfn(current)
1.24 + units.append(current)
1.25 + return units
1.26 +
1.27 class Month(Temporal):
1.28
1.29 "A simple year-month representation."
1.30 @@ -868,26 +888,6 @@
1.31
1.32 return Period([(x - y) for x, y in zip(self.data, start.data)])
1.33
1.34 - def until(self, start, end, nextfn, prevfn):
1.35 -
1.36 - """
1.37 - Return a collection of units of time by starting from the given 'start'
1.38 - and stepping across intervening units until 'end' is reached, using the
1.39 - given 'nextfn' and 'prevfn' to step from one unit to the next.
1.40 - """
1.41 -
1.42 - current = start
1.43 - units = [current]
1.44 - if current < end:
1.45 - while current < end:
1.46 - current = nextfn(current)
1.47 - units.append(current)
1.48 - elif current > end:
1.49 - while current > end:
1.50 - current = prevfn(current)
1.51 - units.append(current)
1.52 - return units
1.53 -
1.54 def months_until(self, end):
1.55
1.56 "Return the collection of months from this month until 'end'."
1.57 @@ -1033,16 +1033,14 @@
1.58 date = self.as_date()
1.59
1.60 # Add the minutes and hours.
1.61 - # NOTE: This makes various assumptions and probably would not work
1.62 - # NOTE: for general arithmetic.
1.63
1.64 minute += minutes
1.65 - if minute < 0:
1.66 - hour -= 1
1.67 - minute += 60
1.68 - elif minute > 59:
1.69 - hour += 1
1.70 - minute -= 60
1.71 + if minute < 0 or minute > 59:
1.72 + hour += minute / 60
1.73 + minute = minute % 60
1.74 +
1.75 + # NOTE: This makes various assumptions and probably would not work
1.76 + # NOTE: for general arithmetic.
1.77
1.78 hour += hours
1.79 if hour < 0:
1.80 @@ -1159,7 +1157,12 @@
1.81 try:
1.82 return self._as_olson_datetime()
1.83 except (pytz.UnknownTimeZoneError, pytz.AmbiguousTimeError):
1.84 - return self._as_olson_datetime(-1)
1.85 +
1.86 + # Try again, using an earlier local time and then stepping forward
1.87 + # in the chosen zone.
1.88 + # NOTE: Four hours earlier seems reasonable.
1.89 +
1.90 + return self._as_olson_datetime(-4)
1.91
1.92 def ambiguous(self):
1.93