Message237527
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. |
|
Date |
User |
Action |
Args |
2015-03-08 10:35:01 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, lemburg, belopolsky |
2015-03-08 10:35:01 | serhiy.storchaka | set | messageid: <1425810901.79.0.570490913636.issue23607@psf.upfronthosting.co.za> |
2015-03-08 10:35:01 | serhiy.storchaka | link | issue23607 messages |
2015-03-08 10:35:01 | serhiy.storchaka | create | |
|