A problem with Time

Roger Miller roger.miller at nova-sol.com
Thu Aug 16 16:49:09 EDT 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
becomes
August 1 and August -1 becomes July 31.  Python presumably inherits
this
very useful (and seemingly not well known) behavior, but it is not
documented.  Is this just an oversight, or is it intentional on the
grounds
that it might be platform-dependent?  Any language lawyers out there
that
would care to comment?




More information about the Python-list mailing list