Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 78371) +++ Modules/timemodule.c (working copy) @@ -382,6 +382,43 @@ return 1; } + +static PyObject * +time_timegm(PyObject *self, PyObject *tup) +{ + struct tm buf; + time_t tt; + if (!gettmarg(tup, &buf)) + return NULL; +#ifdef HAVE_TIMEGM + /* Use timegm function where available */ + tt = timegm(&buf); +#elif defined(HAVE_MKTIME) && defined(HAVE_WORKING_TZSET) + /* Fallback to mktime, taken from timegm(3)*/ + char *tz; + tz = getenv("TZ"); + setenv("TZ", "", 1); + tzset(); + tt = mktime(&buf); + if (tz) + setenv("TZ", "", 1); + else + unsetenv("TZ"); + tzset(); +#endif + if (tt == (time_t)(-1)) { + PyErr_SetString(PyExc_OverflowError, + "timegm argument out of range"); + return NULL; + } + return PyFloat_FromDouble((double)tt); +} + +PyDoc_STRVAR(timegm_doc, +"timegm(tuple) -> Floating point number\n\ +\n\ +Convert a UTC tuple to seconds since the Epoch."); + #ifdef HAVE_STRFTIME static PyObject * time_strftime(PyObject *self, PyObject *args) @@ -773,6 +810,9 @@ {"localtime", time_localtime, METH_VARARGS, localtime_doc}, {"asctime", time_asctime, METH_VARARGS, asctime_doc}, {"ctime", time_ctime, METH_VARARGS, ctime_doc}, +#ifdef HAVE_TIMEGM || (defined(HAVE_MKTIME) && defined(HAVE_WORKING_TZSET)) + {"timegm", time_timegm, METH_O, timegm_doc}, +#endif #ifdef HAVE_MKTIME {"mktime", time_mktime, METH_O, mktime_doc}, #endif @@ -824,6 +864,7 @@ clock() -- return CPU time since process start as a float\n\ sleep() -- delay for a number of seconds given as a float\n\ gmtime() -- convert seconds since Epoch to UTC tuple\n\ +timegm() - Convert a UTC tuple to seconds since the Epoch.\n\ localtime() -- convert seconds since Epoch to local time tuple\n\ asctime() -- convert time tuple to string\n\ ctime() -- convert time in seconds to string\n\