예제 #1
0
        def _next_step(timer):
            current = localtime()
            current_pointer = self.get_current_pointer()
            next_time_pointer = self.get_next_pointer(*current_pointer)

            def is_the_same_callback():
                # Skip callbacks calls when time does not match.
                if next_time_pointer == last_time_pointer:
                    if current_pointer == next_time_pointer:
                        return False
                    return True
                return False

            # There are no new tasks in the future, so we finish
            if next_time_pointer == None:
                if not is_the_same_callback():
                    self.run_callbacks(*last_time_pointer)
                return

            # zero day
            def get_zero_day_time_sec(year, month, mday, hour, minute, second,
                                      weekday, yearday):
                return mktime(
                    current
                ) - weekday * 24 * 60 * 60 - hour * 60 * 60 - minute * 60 - second

            def get_pointer_sec(weekday, hour, minute, second):
                return weekday * 24 * 60 * 60 + hour * 60 * 60 + minute * 60 + second

            zero_day_time_sec = get_zero_day_time_sec(*current)

            period_seconds = zero_day_time_sec + get_pointer_sec(
                *next_time_pointer) - mktime(current)
            period_mili_seconds = self._get_time_change_correction(
                period_seconds * 1000)

            timer.init(period=period_mili_seconds,
                       mode=Timer.ONE_SHOT,
                       callback=self.next_step(*next_time_pointer))

            if not is_the_same_callback():
                self.run_callbacks(*last_time_pointer)
예제 #2
0
 def get_zero_day_time_sec(year, month, mday, hour, minute, second, weekday, yearday):
     return mktime(current) - weekday * 24 * 60 * 60 - hour * 60 * 60 - minute * 60 - second