]> granicus.if.org Git - python/commitdiff
Replaced my dumb way of calculating seconds to midnight with Tim Peters' much more...
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Tue, 2 May 2006 08:35:36 +0000 (08:35 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Tue, 2 May 2006 08:35:36 +0000 (08:35 +0000)
Lib/logging/handlers.py

index 8e569a765d5c0652a056e21cbf7aec22cf604364..e0da254f31f8831c42ae2c38a0ccd9f9de7cc8b8 100644 (file)
@@ -44,6 +44,8 @@ DEFAULT_HTTP_LOGGING_PORT   = 9022
 DEFAULT_SOAP_LOGGING_PORT   = 9023
 SYSLOG_UDP_PORT             = 514
 
+_MIDNIGHT = 24 * 60 * 60  # number of seconds in a day
+
 class BaseRotatingHandler(logging.FileHandler):
     """
     Base class for handlers that rotate log files at a certain point.
@@ -217,12 +219,8 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
             currentMinute = t[4]
             currentSecond = t[5]
             # r is the number of seconds left between now and midnight
-            if (currentMinute == 0) and (currentSecond == 0):
-                r = (24 - currentHour) * 60 * 60 # number of hours in seconds
-            else:
-                r = (23 - currentHour) * 60 * 60
-                r = r + (59 - currentMinute) * 60 # plus the number of minutes (in secs)
-                r = r + (60 - currentSecond) # plus the number of seconds
+            r = _MIDNIGHT - ((currentHour * 60 + currentMinute) * 60 +
+                    currentSecond)
             self.rolloverAt = 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