[Datetime-SIG] The name of the UTC timezone

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Aug 26 16:01:35 CEST 2015


As a little diversion from the PEP wars, let me ask the group if we can fix
this little wart: [1]

>>> from datetime import *
>>> t = datetime.now(timezone.utc)
>>> print(t)
2015-08-26 13:37:18.729831+00:00
>>> t.strftime("%F %T %Z%z")
'2015-08-26 13:37:18 UTC+00:00+0000'

The reason for such an odd result is that the "name" of timezone.utc was
defined as

>>> t.tzname()
'UTC+00:00'

I don't think there was any deep reason for this choice.  We simply have
one common rule for forming the names of all fixed offset timezones that
don't have a name supplied in the constructor:

>>> print(timezone(-5*HOUR))
UTC-05:00

For technical reasons, we cannot give timezone.utc a name, but I think we
can change the rules for forming fixed offset timezone names so that zeros
are not printed and instead of

>>> print(timezone(0*HOUR))
UTC+00:00

we have

>>> print(timezone(0*HOUR))
UTC


[1]: http://bugs.python.org/issue22241
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150826/40e6835b/attachment.html>


More information about the Datetime-SIG mailing list