New submission from Lennart Regebro:

When calling tzname() on a timezone object it will return "UTC" + the offset.

>>> from datetime import timezone, timedelta, datetime
>>> tz = timezone(timedelta(hours=3))
>>> dt = datetime(2013, 3, 14, 12, 30, tzinfo=tz)
>>> dt.tzname()
'UTC+03:00'

But this breaks strftime:

>>> dt.strftime("%Z%z")
'UTC+03:00+0300'

I think that tzname() should never return an offset, and that for the static 
offset "timezone" class should always return 'GMT' for any offset, unless a 
name was explicitly set when creating the timezone instance.

The timezone.utc timezone instance should have the name set to 'UTC'.

This is consistent with how time.tzname works, and hence provides Least 
Surprise:

>>> import time
>>> time.timezone
86400
>>> time.tzname
('PST', 'PDT')

>>> import os
>>> os.environ['TZ'] = 'GMT-3'
>>> time.tzset()
>>> time.timezone
-10800
>>> time.tzname
('GMT', 'GMT')

>>> os.environ['TZ'] = 'UTC'
>>> time.tzset()
>>> time.timezone
0
>>> time.tzname
('UTC', 'UTC')

----------
components: Library (Lib)
messages: 184673
nosy: lregebro
priority: normal
severity: normal
status: open
title: datetime.timezone returns the wrong tzname()
versions: Python 3.3, Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17486>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to