]> granicus.if.org Git - python/commitdiff
Fix: #1836: Off-by-one bug in TimedRotatingFileHandler rollover calculation. Patch...
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 21 Jan 2008 17:03:46 +0000 (17:03 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Mon, 21 Jan 2008 17:03:46 +0000 (17:03 +0000)
Lib/logging/handlers.py

index 67d8576f703b49fba6cd78dde7dfe1b018999e99..1e3e29854c470bd244a58938dfd99b216ad67230 100644 (file)
@@ -229,13 +229,16 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
             #         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 when.startswith('W'):
                 day = t[6] # 0 is Monday
                 if day != self.dayOfWeek:
                     if day < self.dayOfWeek:
-                        daysToWait = self.dayOfWeek - day - 1
+                        daysToWait = self.dayOfWeek - day
                     else:
-                        daysToWait = 6 - day + self.dayOfWeek
+                        daysToWait = 6 - day + self.dayOfWeek + 1
                     self.rolloverAt = self.rolloverAt + (daysToWait * (60 * 60 * 24))
 
         #print "Will rollover at %d, %d seconds from now" % (self.rolloverAt, self.rolloverAt - currentTime)