Marc-Andre Lemburg <m...@egenix.com> added the comment:

JoeKuan wrote:
> 
> JoeKuan <kuan....@gmail.com> added the comment:
> 
> I don't think it is to do with the underlying C mktime. Because it works fine 
> with 00:59:58 and 01:00:00, 1, Jan 1970. It is to do with some specific value 
> -1 in the internal code of time.mktime

Here's the module code:

    buf.tm_wday = -1;  /* sentinel; original value ignored */
    tt = mktime(&buf);
    /* Return value of -1 does not necessarily mean an error, but tm_wday
     * cannot remain set to -1 if mktime succedded. */
    if (tt == (time_t)(-1) && buf.tm_wday == -1) {
        PyErr_SetString(PyExc_OverflowError,
                        "mktime argument out of range");
        return NULL;
    }

This is correct by the books, since the Linux man-page states (the
POSIX page is similar):

"""
       The  mktime()  function  modifies  the fields of the tm structure as 
follows:
       tm_wday and tm_yday are set to values determined from  the  contents  of 
 the
       other  fields;  if  structure  members are outside their valid interval, 
they
       will be normalized (so that, for example, 40 October is changed into 9 
Novem-
       ber);  tm_isdst  is set (regardless of its initial value) to a positive 
value
       or to 0, respectively, to indicate whether DST is or is not in effect at 
 the
       specified time.  Calling mktime() also sets the external variable tzname 
with
       information about the current timezone.

       If the specified broken-down time cannot  be  represented  as  calendar  
time
       (seconds  since  the Epoch), mktime() returns a value of (time_t) -1 and 
does
       not alter the members of the broken-down time structure.
"""

On which platform are you trying this ?

> Here is the C code.
> 
> int main(int argc, char *argv[]) {
> 
>         struct tm aTime = { 58, 59, 0, 1, 0, 70, 0, 0, 0, 0 };
>         time_t mTime = mktime(&aTime);
>         printf("%s\n", ctime(&mTime));
> 
>         aTime.tm_sec = 59;
>         mTime = mktime(&aTime);
>         printf("%s\n", ctime(&mTime));
> 
>         aTime.tm_sec = 0;
>         aTime.tm_min = 0;
>         aTime.tm_hour = 1;
>         mTime = mktime(&aTime);
>         printf("%s\n", ctime(&mTime));
> }
> 
> -------------------------------------------------------
> Output from the same machine which gives the python error message
> 
> 
> Thu Jan  1 00:59:58 1970
> 
> Thu Jan  1 00:59:59 1970
> 
> Thu Jan  1 01:00:00 1970

On Windows, you get errors for the first two.

----------
title: mktime - OverflowError: mktime argument out of range - on very specific 
time -> mktime - OverflowError: mktime argument out of range -   on very 
specific time

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11850>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to