equal
deleted
inserted
replaced
45 HOURS = 'hours' |
45 HOURS = 'hours' |
46 MINUTES = 'minutes' |
46 MINUTES = 'minutes' |
47 |
47 |
48 try: |
48 try: |
49 from pytz import NonExistentTimeError |
49 from pytz import NonExistentTimeError |
|
50 from pytz import AmbiguousTimeError |
50 except ImportError: |
51 except ImportError: |
51 class NonExistentTimeError(Exception): |
52 class NonExistentTimeError(Exception): |
|
53 pass |
|
54 class AmbiguousTimeError(Exception): |
52 pass |
55 pass |
53 |
56 |
54 |
57 |
55 def GrocTimeSpecification(schedule): |
58 def GrocTimeSpecification(schedule): |
56 """Factory function. |
59 """Factory function. |
117 period - the type of interval, either "hours" or "minutes" |
120 period - the type of interval, either "hours" or "minutes" |
118 interval - the number of units of type period. |
121 interval - the number of units of type period. |
119 """ |
122 """ |
120 |
123 |
121 def __init__(self, interval, period): |
124 def __init__(self, interval, period): |
122 super(IntervalTimeSpecification, self).__init__(self) |
125 super(IntervalTimeSpecification, self).__init__() |
123 self.interval = interval |
126 self.interval = interval |
124 self.period = period |
127 self.period = period |
125 |
128 |
126 def GetMatch(self, t): |
129 def GetMatch(self, t): |
127 """Returns the next match after time 't'. |
130 """Returns the next match after time 't'. |
284 |
287 |
285 minute=self.time.minute, second=0, |
288 minute=self.time.minute, second=0, |
286 microsecond=0) |
289 microsecond=0) |
287 if self.timezone and pytz is not None: |
290 if self.timezone and pytz is not None: |
288 try: |
291 try: |
|
292 out = self.timezone.localize(out, is_dst=None) |
|
293 except AmbiguousTimeError: |
289 out = self.timezone.localize(out) |
294 out = self.timezone.localize(out) |
290 except (NonExistentTimeError, IndexError): |
295 except NonExistentTimeError: |
291 for _ in range(24): |
296 for _ in range(24): |
292 out = out.replace(minute=1) + datetime.timedelta(minutes=60) |
297 out = out.replace(minute=1) + datetime.timedelta(minutes=60) |
293 try: |
298 try: |
294 out = self.timezone.localize(out) |
299 out = self.timezone.localize(out) |
295 except (NonExistentTimeError, IndexError): |
300 except NonExistentTimeError: |
296 continue |
301 continue |
297 break |
302 break |
298 out = out.astimezone(pytz.utc) |
303 out = out.astimezone(pytz.utc) |
299 return out |
304 return out |