New submission from Serhiy Storchaka: First, datetime.utcfromtimestamp() drops fractional part of Decimal argument:
>>> import datetime >>> from decimal import Decimal as D >>> datetime.datetime.utcfromtimestamp(1425808327.307651) datetime.datetime(2015, 3, 8, 9, 52, 7, 307651) >>> datetime.datetime.utcfromtimestamp(D(1425808327.307651)) datetime.datetime(2015, 3, 8, 9, 52, 7) Second, it works only with C implementation. With Python implementation Decimals are not supported at all. >>> del sys.modules['datetime'] >>> sys.modules['_datetime'] = None >>> import datetime >>> datetime.datetime.utcfromtimestamp(D(1425808327.307651)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.4/datetime.py", line 1374, in utcfromtimestamp t, frac = divmod(t, 1.0) TypeError: unsupported operand type(s) for divmod(): 'decimal.Decimal' and 'float' In 2.7 Decimals are accepted and are not truncated. >>> import datetime >>> from decimal import Decimal as D >>> datetime.datetime.utcfromtimestamp(D(1425808327.307651)) datetime.datetime(2015, 3, 8, 9, 52, 7, 307651) So this can be considered as a regression. ---------- components: Library (Lib) messages: 237527 nosy: belopolsky, lemburg, serhiy.storchaka priority: normal severity: normal status: open title: Inconsistency in datetime.utcfromtimestamp(Decimal) type: behavior versions: Python 3.4, Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23607> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com