@@ -172,7 +172,6 @@ def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None,
172172 #
173173 # Case of the 'when' specifier is not important; lower or upper case
174174 # will work.
175- currentTime = int (time .time ())
176175 if self .when == 'S' :
177176 self .interval = 1 # one second
178177 self .suffix = "%Y-%m-%d_%H-%M-%S"
@@ -203,8 +202,13 @@ def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None,
203202
204203 self .extMatch = re .compile (self .extMatch , re .ASCII )
205204 self .interval = self .interval * interval # multiply by units requested
206- self .rolloverAt = currentTime + self .interval
205+ self .rolloverAt = self .computeRollover ( int ( time . time ()))
207206
207+ def computeRollover (self , currentTime ):
208+ """
209+ Work out the rollover time based on the specified time.
210+ """
211+ result = currentTime + self .interval
208212 # If we are rolling over at midnight or weekly, then the interval is already known.
209213 # What we need to figure out is WHEN the next interval is. In other words,
210214 # if you are rolling over at midnight, then your base interval is 1 day,
@@ -214,7 +218,7 @@ def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None,
214218 # the rest. Note that this code doesn't care about leap seconds. :)
215219 if self .when == 'MIDNIGHT' or self .when .startswith ('W' ):
216220 # This could be done with less code, but I wanted it to be clear
217- if utc :
221+ if self . utc :
218222 t = time .gmtime (currentTime )
219223 else :
220224 t = time .localtime (currentTime )
@@ -224,7 +228,7 @@ def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None,
224228 # r is the number of seconds left between now and midnight
225229 r = _MIDNIGHT - ((currentHour * 60 + currentMinute ) * 60 +
226230 currentSecond )
227- self . rolloverAt = currentTime + r
231+ result = currentTime + r
228232 # If we are rolling over on a certain day, add in the number of days until
229233 # the next rollover, but offset by 1 since we just calculated the time
230234 # until the next day starts. There are three cases:
@@ -240,25 +244,24 @@ def __init__(self, filename, when='h', interval=1, backupCount=0, encoding=None,
240244 # The calculations described in 2) and 3) above need to have a day added.
241245 # This is because the above time calculation takes us to midnight on this
242246 # day, i.e. the start of the next day.
243- if when .startswith ('W' ):
247+ if self . when .startswith ('W' ):
244248 day = t [6 ] # 0 is Monday
245249 if day != self .dayOfWeek :
246250 if day < self .dayOfWeek :
247251 daysToWait = self .dayOfWeek - day
248252 else :
249253 daysToWait = 6 - day + self .dayOfWeek + 1
250- newRolloverAt = self . rolloverAt + (daysToWait * (60 * 60 * 24 ))
251- if not utc :
254+ newRolloverAt = result + (daysToWait * (60 * 60 * 24 ))
255+ if not self . utc :
252256 dstNow = t [- 1 ]
253257 dstAtRollover = time .localtime (newRolloverAt )[- 1 ]
254258 if dstNow != dstAtRollover :
255259 if not dstNow : # DST kicks in before next rollover, so we need to deduct an hour
256260 newRolloverAt = newRolloverAt - 3600
257261 else : # DST bows out before next rollover, so we need to add an hour
258262 newRolloverAt = newRolloverAt + 3600
259- self .rolloverAt = newRolloverAt
260-
261- #print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)
263+ result = newRolloverAt
264+ return result
262265
263266 def shouldRollover (self , record ):
264267 """
@@ -327,8 +330,8 @@ def doRollover(self):
327330 #print "%s -> %s" % (self.baseFilename, dfn)
328331 self .mode = 'w'
329332 self .stream = self ._open ()
330- newRolloverAt = self .rolloverAt + self .interval
331333 currentTime = int (time .time ())
334+ newRolloverAt = self .computeRollover (currentTime )
332335 while newRolloverAt <= currentTime :
333336 newRolloverAt = newRolloverAt + self .interval
334337 #If DST changes and midnight or weekly rollover, adjust for this.
0 commit comments