A problem with Time

Roger Miller roger.miller at nova-sol.com
Thu Aug 16 22:49:09 CEST 2007

On Aug 16, 9:46 am, MRAB <goo... at mrabarnett.plus.com> wrote:
> As well as the other replies, this also works (as far as I can tell!):
> import time
> today = time.localtime()
> yesterday = today[ : 2] + (today[2] - 1, ) + today[3 : ]
> yesterday = time.localtime(time.mktime(yesterday))

This is something I have wondered about.  The C library mktime
function is
documented to fix up out of range values,.  For example July 32
August 1 and August -1 becomes July 31.  Python presumably inherits
very useful (and seemingly not well known) behavior, but it is not
documented.  Is this just an oversight, or is it intentional on the
that it might be platform-dependent?  Any language lawyers out there
would care to comment?

More information about the Python-list mailing list