Index: Lib/test/test_time.py =================================================================== --- Lib/test/test_time.py (revision 81646) +++ Lib/test/test_time.py (working copy) @@ -218,6 +218,22 @@ t1 = time.mktime(lt1) self.assertTrue(0 <= (t1-t0) < 0.2) + @unittest.skipUnless(hasattr(time.struct_time, "tm_zone"), + "struct tm does not have tm_zone field") + def test_tm_zone(self): + t = time.gmtime(0) + self.assertEqual(t.tm_zone, 'UTC') + self.assertEqual(t.tm_gmtoff, 0) + + lt = time.localtime() + self.assertEqual(lt.tm_zone, time.tzname[lt.tm_isdst]) + self.assertEqual(lt.tm_gmtoff, -[time.timezone, time.altzone][lt.tm_isdst]) + + # Check that struct_time still behaves as a 9-tuple + self.assertEqual(len(lt), 9) + self.assertRaises(IndexError, t.__getitem__, 9) + self.assertEqual(lt.tm_isdst, lt[-1]) + class TestLocale(unittest.TestCase): def setUp(self): self.oldloc = locale.setlocale(locale.LC_ALL) Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 81646) +++ Modules/timemodule.c (working copy) @@ -217,6 +217,10 @@ {"tm_wday", NULL}, {"tm_yday", NULL}, {"tm_isdst", NULL}, +#ifdef HAVE_STRUCT_TM_TM_ZONE + {"tm_zone", "abbreviation of timezone name"}, + {"tm_gmtoff", "offset from UTC in seconds"}, +#endif /* HAVE_STRUCT_TM_TM_ZONE */ {0} }; @@ -248,6 +252,10 @@ 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 + PyStructSequence_SET_ITEM(v, 9, PyUnicode_FromString(p->tm_zone)); + SET(10, p->tm_gmtoff); +#endif /* HAVE_STRUCT_TM_TM_ZONE */ #undef SET if (PyErr_Occurred()) { Py_XDECREF(v);