summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2008-01-21 17:02:26 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2008-01-21 17:02:26 (GMT)
commitae747dccab69cb3828a3d51fafe41021f50882c9 (patch)
tree0e11852146d419d542983d8ce56cb4293b1f2d5f /Lib/logging
parentaa0de3f130f74c8551cdf9b798447fafd305fe3a (diff)
downloadcpython-ae747dccab69cb3828a3d51fafe41021f50882c9.zip
cpython-ae747dccab69cb3828a3d51fafe41021f50882c9.tar.gz
cpython-ae747dccab69cb3828a3d51fafe41021f50882c9.tar.bz2
Fix: #1836: Off-by-one bug in TimedRotatingFileHandler rollover calculation. Patch thanks to Kathryn M. Kowalski.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index fa203cf..93fcd83 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -228,13 +228,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)