(self, currentTime)
return result
Work out the rollover time based on the specified time.
Work out the rollover time based on the specified time.
Work out the rollover time based on the specified time .
def computeRollover(self, currentTime):
        """
        Work out the rollover time based on the specified time.
        """
        result = currentTime + self.interval
        # If we are rolling over at midnight or weekly, then the interval is already known.
        # What we need to figure out is WHEN the next interval is.  In other words,
        # if you are rolling over at midnight, then your base interval is 1 day,
        # but you want to start that one day clock at midnight, not now.  So, we
        # have to fudge the rolloverAt value in order to trigger the first rollover
        # at the right time.  After that, the regular interval will take care of
        # the rest.  Note that this code doesn't care about leap seconds. :)
        if self.when == 'MIDNIGHT' or self.when.startswith('W'):
            # This could be done with less code, but I wanted it to be clear
            if self.utc:
                t = time.gmtime(currentTime)
            else:
                t = time.localtime(currentTime)
            currentHour = t[3]
            currentMinute = t[4]
            currentSecond = t[5]
            # r is the number of seconds left between now and midnight
            r = _MIDNIGHT - ((currentHour * 60 + currentMinute) * 60 +
                    currentSecond)
            result = currentTime + r
            # If we are rolling over on a certain day, add in the number of days until
            # the next rollover, but offset by 1 since we just calculated the time
            # until the next day starts.  There are three cases:
            # Case 1) The day to rollover is today; in this case, do nothing
            # Case 2) The day to rollover is further in the interval (i.e., today is
            #         day 2 (Wednesday) and rollover is on day 6 (Sunday).  Days to
            #         next rollover is simply 6 - 2 - 1, or 3.
            # Case 3) The day to rollover is behind us in the interval (i.e., today
            #         is day 5 (Saturday) and rollover is on day 3 (Thursday).
            #         Days to rollover is 6 - 5 + 3, or 4.  In this case, it's the
            #         number of days left in the current week (1) plus the number
            #         of days in the next week until the rollover day (3).
            # The calculations described in 2) and 3) above need to have a day added.
            # This is because the above time calculation takes us to midnight on this
            # day, i.e. the start of the next day.
            if self.when.startswith('W'):
                day = t[6] # 0 is Monday
                if day != self.dayOfWeek:
                    if day < self.dayOfWeek:
                        daysToWait = self.dayOfWeek - day
                    else:
                        daysToWait = 6 - day + self.dayOfWeek + 1
                    newRolloverAt = result + (daysToWait * (60 * 60 * 24))
                    if not self.utc:
                        dstNow = t[-1]
                        dstAtRollover = time.localtime(newRolloverAt)[-1]
                        if dstNow != dstAtRollover:
                            if not dstNow:  # DST kicks in before next rollover, so we need to deduct an hour
                                newRolloverAt = newRolloverAt - 3600
                            else:           # DST bows out before next rollover, so we need to add an hour
                                newRolloverAt = newRolloverAt + 3600
                    result = newRolloverAt
        return result
def computeRollover ( self , currentTime ) : result = currentTime + self . interval # If we are rolling over at midnight or weekly, then the interval is already known. # What we need to figure out is WHEN the next interval is.  In other words, # if you are rolling over at midnight, then your base interval is 1 day, # but you want to start that one day clock at midnight, not now.  So, we # have to fudge the rolloverAt value in order to trigger the first rollover # at the right time.  After that, the regular interval will take care of # the rest.  Note that this code doesn't care about leap seconds. :) if self . when == 'MIDNIGHT' or self . when . startswith ( 'W' ) : # This could be done with less code, but I wanted it to be clear if self . utc : t = time . gmtime ( currentTime ) else : t = time . localtime ( currentTime ) currentHour = t [ 3 ] currentMinute = t [ 4 ] currentSecond = t [ 5 ] # r is the number of seconds left between now and midnight r = _MIDNIGHT - ( ( currentHour * 60 + currentMinute ) * 60 + currentSecond ) result = currentTime + r # If we are rolling over on a certain day, add in the number of days until # the next rollover, but offset by 1 since we just calculated the time # until the next day starts.  There are three cases: # Case 1) The day to rollover is today; in this case, do nothing # Case 2) The day to rollover is further in the interval (i.e., today is #         day 2 (Wednesday) and rollover is on day 6 (Sunday).  Days to #         next rollover is simply 6 - 2 - 1, or 3. # Case 3) The day to rollover is behind us in the interval (i.e., today #         is day 5 (Saturday) and rollover is on day 3 (Thursday). #         Days to rollover is 6 - 5 + 3, or 4.  In this case, it's the #         number of days left in the current week (1) plus the number #         of days in the next week until the rollover day (3). # The calculations described in 2) and 3) above need to have a day added. # This is because the above time calculation takes us to midnight on this # day, i.e. the start of the next day. if self . when . startswith ( 'W' ) : day = t [ 6 ] # 0 is Monday if day != self . dayOfWeek : if day < self . dayOfWeek : daysToWait = self . dayOfWeek - day else : daysToWait = 6 - day + self . dayOfWeek + 1 newRolloverAt = result + ( daysToWait * ( 60 * 60 * 24 ) ) if not self . utc : dstNow = t [ - 1 ] dstAtRollover = time . localtime ( newRolloverAt ) [ - 1 ] if dstNow != dstAtRollover : if not dstNow : # DST kicks in before next rollover, so we need to deduct an hour newRolloverAt = newRolloverAt - 3600 else : # DST bows out before next rollover, so we need to add an hour newRolloverAt = newRolloverAt + 3600 result = newRolloverAt return result