[issue36899] datetime utcfromtimestamp ignores astimezone
New submission from Piotr Kamoda : See below code: >>> datetime.utcfromtimestamp(1557395250).astimezone(get_localzone()).strftime('%Y-%m-%d >>> %H:%M:%S %z %Z') '2019-05-09 09:47:30 +0200 CEST' >>> datetime.fromtimestamp(1557395250).astimezone(get_localzone()).strftime('%Y-%m-%d >>> %H:%M:%S %z %Z') '2019-05-09 11:47:30 +0200 CEST' As you can see, utcfromtimestamp refuses to be 'timezoned', second one is correct. -- messages: 342297 nosy: Piotr Kamoda priority: normal severity: normal status: open title: datetime utcfromtimestamp ignores astimezone versions: Python 3.7 ___ Python tracker <https://bugs.python.org/issue36899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36899] datetime utcfromtimestamp ignores astimezone
Piotr Kamoda added the comment: Docs state that fromtimestamp returns a naive datetime object (https://docs.python.org/3.7/library/datetime.html#datetime.datetime.fromtimestamp) and not utcfromtimestamp. Perhaps it needs fixing. Additionally, astimezone fails silently, I even tried >>> datetime.utcfromtimestamp(1557395250).astimezone(pytz.utc).astimezone(get_localzone()).strftime('%Y-%m-%d >>> %H:%M:%S %z %Z') '2019-05-09 09:47:30 +0200 CEST' Which looks weird, but why it ignores that function silently is also weird. -- ___ Python tracker <https://bugs.python.org/issue36899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue36899] datetime utcfromtimestamp ignores astimezone
Piotr Kamoda added the comment: Ok, now I see that naive object assumes my timezone in some cases. That's still mind-boggling that utcfromtimestamp returns an object that shows utc hour but when astimezone is applied it reverts without converting the hour to local timezone. See below as explanation: >>> datetime.utcfromtimestamp(1557395250).astimezone(pytz.utc).strftime('%Y-%m-%d >>> %H:%M:%S %z %Z') '2019-05-09 07:47:30 + UTC' >>> datetime.utcfromtimestamp(1557395250).astimezone(get_localzone()).strftime('%Y-%m-%d >>> %H:%M:%S %z %Z') '2019-05-09 09:47:30 +0200 CEST' -- ___ Python tracker <https://bugs.python.org/issue36899> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com