diff -r c2217813dbab Lib/test/test_time.py --- a/Lib/test/test_time.py Fri Feb 23 12:05:41 2007 +0100 +++ b/Lib/test/test_time.py Thu Mar 08 01:20:39 2007 +0100 @@ -202,6 +202,17 @@ class TimeTestCase(unittest.TestCase): t1 = time.mktime(time.localtime(None)) self.assert_(0 <= (t1-t0) < 0.2) + def test_localtime_timezone(self): + lt = time.localtime() + self.assert_(hasattr(lt, "tm_gmtoff")) + t = time.mktime(lt); t9 = time.mktime(lt[:9]) + self.assert_(t == t9) + new_lt = time.localtime(t); new_lt9 = time.localtime(t9) + self.assert_(new_lt == lt) + self.assert_(new_lt.tm_gmtoff == lt.tm_gmtoff) + self.assert_(new_lt9 == lt) + self.assert_(new_lt9.tm_gmtoff == lt.tm_gmtoff) + def test_main(): test_support.run_unittest(TimeTestCase) diff -r c2217813dbab Modules/timemodule.c --- a/Modules/timemodule.c Fri Feb 23 12:05:41 2007 +0100 +++ b/Modules/timemodule.c Thu Mar 08 01:20:39 2007 +0100 @@ -231,6 +231,7 @@ static PyStructSequence_Field struct_tim {"tm_wday", NULL}, {"tm_yday", NULL}, {"tm_isdst", NULL}, + {"tm_gmtoff", NULL}, {0} }; @@ -261,6 +262,12 @@ tmtotuple(struct tm *p) SET(6, (p->tm_wday + 6) % 7); /* Want Monday == 0 */ SET(7, p->tm_yday + 1); /* Want January, 1 == 1 */ SET(8, p->tm_isdst); +#ifdef HAVE_STRUCT_TM_TM_ZONE + SET(9, p->tm_gmtoff); +#else + PyStructSequence_SET_ITEM(v, 9, Py_None); + Py_INCREF(Py_None); +#endif #undef SET if (PyErr_Occurred()) { Py_XDECREF(v); @@ -341,7 +348,13 @@ PyDoc_STRVAR(localtime_doc, "localtime([seconds]) -> (tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)\n\ \n\ Convert seconds since the Epoch to a time tuple expressing local time.\n\ -When 'seconds' is not passed in, convert the current time instead."); +When 'seconds' is not passed in, convert the current time instead.\n\ +\n\ +If time zone information is available, the tm_gmtoff attribute may be\n\ +consulted on the time tuple to obtain the location of the associated\n\ +time zone in seconds east of GMT/UTC; thus the value may be negative\n\ +for time zones west of the prime meridian, for example. Where no time\n\ +zone information is available, tm_gmtoff will be None."); static int gettmarg(PyObject *args, struct tm *p) @@ -360,6 +373,14 @@ gettmarg(PyObject *args, struct tm *p) &p->tm_yday, &p->tm_isdst)) return 0; +#ifdef HAVE_STRUCT_TM_TM_ZONE + /* Add GMT/UTC offset where a time structure is provided. */ + if (PyType_IsSubtype(args->ob_type, &StructTimeType)) { + PyObject *gmtoff = ((PyStructSequence *)(args))->ob_item[9]; + if (gmtoff != Py_None) + p->tm_gmtoff = PyInt_AsLong(gmtoff); + } +#endif if (y < 1900) { PyObject *accept = PyDict_GetItemString(moddict, "accept2dyear");