diff -r bf789ae9bde7 Doc/library/datetime.rst --- a/Doc/library/datetime.rst Fri Aug 28 10:36:01 2015 +1200 +++ b/Doc/library/datetime.rst Fri Aug 28 11:40:41 2015 -0400 @@ -1734,10 +1734,7 @@ otherwise :exc:`ValueError` is raised. The *name* argument is optional. If specified it must be a string that - is used as the value returned by the ``tzname(dt)`` method. Otherwise, - ``tzname(dt)`` returns a string 'UTCsHH:MM', where s is the sign of - *offset*, HH and MM are two digits of ``offset.hours`` and - ``offset.minutes`` respectively. + will be used as the value returned by the ``tzname(dt)`` method. .. versionadded:: 3.2 @@ -1750,11 +1747,16 @@ .. method:: timezone.tzname(dt) - Return the fixed value specified when the :class:`timezone` instance is - constructed or a string 'UTCsHH:MM', where s is the sign of - *offset*, HH and MM are two digits of ``offset.hours`` and + Return the fixed value specified when the :class:`timezone` instance + is constructed. If ``name`` is not provided in the constructor, the + name returned by ``tzname(dt)`` is generated from the value of the + ``offset`` as follows. If ``offset`` is ``timedelta(0)``, the name + is "UTC", otherwise it is a string 'UTC±HH:MM', where ± is the sign + of ``offset``, HH and MM are two digits of ``offset.hours`` and ``offset.minutes`` respectively. + .. versionchanged:: 3.6 + .. method:: timezone.dst(dt) Always returns ``None``. diff -r bf789ae9bde7 Lib/datetime.py --- a/Lib/datetime.py Fri Aug 28 10:36:01 2015 +1200 +++ b/Lib/datetime.py Fri Aug 28 11:40:41 2015 -0400 @@ -1918,6 +1918,8 @@ @staticmethod def _name_from_offset(delta): + if not delta: + return 'UTC' if delta < timedelta(0): sign = '-' delta = -delta diff -r bf789ae9bde7 Lib/test/datetimetester.py --- a/Lib/test/datetimetester.py Fri Aug 28 10:36:01 2015 +1200 +++ b/Lib/test/datetimetester.py Fri Aug 28 11:40:41 2015 -0400 @@ -258,7 +258,8 @@ with self.assertRaises(TypeError): self.EST.dst(5) def test_tzname(self): - self.assertEqual('UTC+00:00', timezone(ZERO).tzname(None)) + self.assertEqual('UTC', timezone.utc.tzname(None)) + self.assertEqual('UTC', timezone(ZERO).tzname(None)) self.assertEqual('UTC-05:00', timezone(-5 * HOUR).tzname(None)) self.assertEqual('UTC+09:30', timezone(9.5 * HOUR).tzname(None)) self.assertEqual('UTC-00:01', timezone(timedelta(minutes=-1)).tzname(None)) diff -r bf789ae9bde7 Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Fri Aug 28 10:36:01 2015 +1200 +++ b/Modules/_datetimemodule.c Fri Aug 28 11:40:41 2015 -0400 @@ -3287,6 +3287,11 @@ Py_INCREF(self->name); return self->name; } + if (self == PyDateTime_TimeZone_UTC || + (GET_TD_DAYS(self->offset) == 0 && + GET_TD_SECONDS(self->offset) == 0 && + GET_TD_MICROSECONDS(self->offset) == 0)) + return PyUnicode_FromString("UTC"); /* Offset is normalized, so it is negative if days < 0 */ if (GET_TD_DAYS(self->offset) < 0) { sign = '-';