[Python-Dev] [Python-checkins] r42064 - python/trunk/Lib/logging/handlers.py (original) (raw)

Tim Peters tim.peters at gmail.com
Mon Jan 16 17:09:20 CET 2006


[vinay]

Log: Fixed bug in time-to-midnight calculation.

[Skip]

Is there some reason not to use datetime to do this?

PEP 291 says logging intends to be compatible with Python 1.5.2, which leaves datetime out.

Vinay, rather than:

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) # pl

for clarity I suggest this instead:

A module-level constant

_MIDNIGHT = 24 * 60 * 60 # number of seconds in a day

r = _MIDNIGHT - ((currentHour * 60 + currentMinute) * 60 + currentSecond)

That's "obviously correct" instead of "huh?" .



More information about the Python-Dev mailing list