[issue23517] datetime.utcfromtimestamp parses timestamps incorrectly

STINNER Victor report at bugs.python.org
Wed Feb 25 18:31:56 CET 2015


STINNER Victor added the comment:

> Would you consider going back to round to nearest?

I don't understand "nearest". I prefer to use names of decimal rounding modes:
https://docs.python.org/dev/library/decimal.html#rounding-modes

In my local patch, I'm using ROUND_FLOOR in _decimal: "Round towards -Infinity."

> Mark and I put in a lot of effort to get the rounding in the datetime module right.  (See for example, #8860.)

I'm unable right now to say which rounding mode should be used in the decimal module. But it's important to use the same rounding mode for all similar operations. For example, time.time() and datetime.datetime.now() should have the same rounding method (bad example, time.time() returns a float, which doesn't round the result).

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

- datetime.date.fromtimestamp()
- datetime.datetime.fromtimestamp()
- datetime.datetime.now()
- datetime.datetime.utcnow()
- os.utime()
- time.clock_settime()
- time.gmtime()
- time.localtime()
- time.ctime()

Note: the Python implementation of datetime uses time.localtime() and time.gmtime() for fromtimestamp(), so these functions should also have the same rounding method.

----------

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


More information about the Python-bugs-list mailing list