New submission from Maksym Shalenyi (Enkidulan) <[email protected]>:
In some cases datetime.time.isoformat shows timezone info, but in some does
not. Consider the example below.
import datetime
import pytz
t = dict(hour=12, minute=31, second=21, microsecond=213456)
# `datetime.time.isoformat` has inconsistent behavior. Some of printed has
timezone, but others does not.
print(datetime.time(tzinfo=pytz.timezone('Asia/Seoul'), **t).isoformat())
print(datetime.time(tzinfo=pytz.timezone('Etc/GMT-9'), **t).isoformat())
print(datetime.time(tzinfo=pytz.timezone('Australia/Sydney'), **t).isoformat())
print(datetime.time(tzinfo=pytz.timezone('Etc/UTC'), **t).isoformat())
# output:
# 12:31:21.213456
# 12:31:21.213456+09:00
# 12:31:21.213456
# 12:31:21.213456+00:00
# `datetime.time.isoformat` is inconsistent with `datetime.datetime.isoformat`.
`datetime` objects always shows tz information when tz is present.
d = dict(year=2018, month=2, day=2, **t)
print(datetime.datetime(tzinfo=pytz.timezone('Asia/Seoul'), **d).isoformat())
print(datetime.datetime(tzinfo=pytz.timezone('Etc/GMT-9'), **d).isoformat())
print(datetime.datetime(tzinfo=pytz.timezone('Australia/Sydney'),
**d).isoformat())
print(datetime.datetime(tzinfo=pytz.timezone('Etc/UTC'), **d).isoformat())
# output:
# 2018-02-02T12:31:21.213456+08:28
# 2018-02-02T12:31:21.213456+09:00
# 2018-02-02T12:31:21.213456+10:05
# 2018-02-02T12:31:21.213456+00:00
----------
components: ctypes
messages: 323531
nosy: Maksym Shalenyi (Enkidulan)
priority: normal
severity: normal
status: open
title: datetime.time.isoformat function has inconsistent behavior with timezone
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34407>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com