Index: Lib/test/test_time.py =================================================================== --- Lib/test/test_time.py (revision 75292) +++ Lib/test/test_time.py (working copy) @@ -213,6 +213,12 @@ t1 = time.mktime(lt1) self.assertTrue(0 <= (t1-t0) < 0.2) + def test_timegm(self): + # test every ten days between min and max timestamp + ts_min, ts_max = -68*365*24*60*60, 68*365*24*60*60 + for ts in range(ts_min, ts_max, 10*24*60*60): + self.assertEqual(time.timegm(time.gmtime(ts)), ts) + def test_main(): test_support.run_unittest(TimeTestCase) Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 75292) +++ Modules/timemodule.c (working copy) @@ -324,6 +324,26 @@ GMT). When 'seconds' is not passed in, convert the current time instead."); static PyObject * +time_timegm(PyObject *self, PyObject *args) +{ + PyObject *calendar_module = PyImport_ImportModuleNoBlock("calendar"); + PyObject *timegm_result; + + if (!calendar_module) + return NULL; + + timegm_result = PyObject_CallMethod(calendar_module, + "timegm", "O", args); + Py_DECREF(calendar_module); + return timegm_result; +} + +PyDoc_STRVAR(timegm_doc, +"timegm(time tuple) -> seconds\n\ +\n\ +Convert a time tuple expressing UTC (a.k.a. GMT) to seconds since the Epoch."); + +static PyObject * time_localtime(PyObject *self, PyObject *args) { double when; @@ -770,6 +790,7 @@ #endif {"sleep", time_sleep, METH_VARARGS, sleep_doc}, {"gmtime", time_gmtime, METH_VARARGS, gmtime_doc}, + {"timegm", time_timegm, METH_VARARGS, timegm_doc}, {"localtime", time_localtime, METH_VARARGS, localtime_doc}, {"asctime", time_asctime, METH_VARARGS, asctime_doc}, {"ctime", time_ctime, METH_VARARGS, ctime_doc}, @@ -824,6 +845,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 UTC tuple to seconds since 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\