[issue23517] datetime.utcfromtimestamp parses timestamps incorrectly

Alexander Belopolsky report at bugs.python.org
Wed Feb 25 18:57:09 CET 2015


Alexander Belopolsky added the comment:

> For example, in my local patch, I'm using ROUND_FLOOR for:

> - datetime.date.fromtimestamp()
> - datetime.datetime.fromtimestamp()

These should use ROUND_HALF_EVEN

> - datetime.datetime.now()
> - datetime.datetime.utcnow()

These should not involve floating point arithmetics, but when converting from nanoseconds to microseconds, you should round to nearest 1000 ns with 500 ns ties resolved to even number of microseconds.


> - os.utime()

This takes nanoseconds as an optional argument.  Passing floats in times should probably be deprecated. In any case, here you would be rounding floats to nanoseconds and what you do with 0.5 nanoseconds is less important because in most cases they are not even representable as floats.

> - time.clock_settime()

Is this a new method?  I don't see it in 3.5.0a1.

> - time.gmtime()

This should be fixed

>>> time.gmtime(1.999999999).tm_sec
1

is really bad and

>>> time.gmtime(-1.999999999)[:6]
(1969, 12, 31, 23, 59, 59)

is probably even worse. 


> - time.localtime()
> - time.ctime()

Same story as in time.gmtime.

----------

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


More information about the Python-bugs-list mailing list