Beispiel #1
0
  def test_sunset_next(self):
    helper = repeat.sunset_helper(LATITUDE, LONGITUDE)
    expected = datetime(2012, 12, 9, 4, 47, 24)

    now = datetime(2012, 12, 9, 0, 32, 49)
    self._almost_timedates(helper(now), expected)

    now = expected - timedelta(seconds=1)
    self._almost_timedates(helper(now), expected)

    now = expected + timedelta(seconds=1)
    expected_next = datetime(2012, 12, 10, 4, 48, 0)
    self._almost_timedates(helper(now), expected_next)
Beispiel #2
0
    def __init__(self, engine, status, url, rule):
        super(_DailyHelper, self).__init__(engine, status, url, rule)

        latitude = float(self._status.get('status://server/latitude'))
        longitude = float(self._status.get('status://server/longitude'))

        # The _find_next_fire_time is a method that returns the datetime in which to
        # next fire if passed utcnow as a datetime. The different implementations of
        # it are how we adjust for different types of daily rules.

        if self._rule['time'] == 'sunset':
            self._find_next_fire_time = repeat.sunset_helper(
                latitude, longitude)
        elif self._rule['time'] == 'sunrise':
            self._find_next_fire_time = repeat.sunrise_helper(
                latitude, longitude)
        else:
            # Else we expect time to be in the format 'hh:mm:ss'
            hours, minutes, seconds = [
                int(i) for i in self._rule['time'].split(':')
            ]
            time_of_day = datetime.time(hours, minutes, seconds)
            self._find_next_fire_time = repeat.daily_helper(time_of_day)