Can I trust mktime ?
Martin von Loewis
loewis at informatik.hu-berlin.de
Sun Dec 23 18:51:05 EST 2001
Tim Howarth <tim at worthy.demon.co.uk> writes:
> To find the date in 4 months time I've added to the months element of a
> list copy of a localtime tuple.
>
> (Which obvioulsy means months can be >12.)
>
> Is converting this to a time() value with mktime then reading back with
> localtime() considered correct/safe ?
On a POSIX system, that might be safe. The mktime(3) documentation of
glibc says
# If structure members are outside their legal interval, they will be
# normalized (so that, e.g., 40 October is changed into 9 November).
I haven't actually verified that this is the POSIX semantics of the
function, though. In any case, Python delegates this call to the C
library, so you are left to the mercy of the C library's implementors.
HTH,
Martin
More information about the Python-list
mailing list