[New-bugs-announce] [issue22791] datetime.utcfromtimestamp() shoud have option for create tz aware datetime

INADA Naoki report at bugs.python.org
Tue Nov 4 09:44:40 CET 2014


New submission from INADA Naoki:

In [1]: import datetime

In [2]: datetime.datetime.utcfromtimestamp(0)
Out[2]: datetime.datetime(1970, 1, 1, 0, 0)

In [3]: datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc)
Out[3]: datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)

datetime.utcfromtimestamp() returns naive datetime.
But some methods assumes naive datetime is localtime. (e.g. datetime.timestamp()).
This is big pitfall for many Pythonistas.

We can't change default behavior for backward compatibility.
How about adding `aware` keyword-only option?

>>> datetime.datetime.utcfromtimestamp(0, aware=True)
datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)

----------
components: Library (Lib)
messages: 230592
nosy: naoki
priority: normal
severity: normal
status: open
title: datetime.utcfromtimestamp() shoud have option for create tz aware datetime
type: enhancement
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22791>
_______________________________________


More information about the New-bugs-announce mailing list