STINNER Victor <vstin...@python.org> added the comment:

> Presumably if we change these two to be consistent, this issue will go away. 
> I am not entirely sure if anyone is relying on a particular rounding behavior 
> for one or both of these, and I'm not sure which one is the right one to 
> harmonize on.

We already changed datetime rounding once in Python 3.4.4, see bpo-23517.

commit 511491ade0bb77febb176bc75f049797f0c71ed0
Author: Victor Stinner <victor.stin...@gmail.com>
Date:   Fri Sep 18 14:42:05 2015 +0200

    Issue #23517: Fix rounding in fromtimestamp() and utcfromtimestamp() methods
    of datetime.datetime: microseconds are now rounded to nearest with ties 
going
    to nearest even integer (ROUND_HALF_EVEN), instead of being rounding towards
    zero (ROUND_DOWN). It's important that these methods use the same rounding
    mode than datetime.timedelta to keep the property:
    
       (datetime(1970,1,1) + timedelta(seconds=t)) == 
datetime.utcfromtimestamp(t)
    
    It also the rounding mode used by round(float) for example.
    
    Add more unit tests on the rounding mode in test_datetime.

Since that time, I wrote a lot of time in Python/pytime.c to handle various 
rounding methods, and handle various time formats. See 
Include/cpython/pytime.h, I added documentation at the top recently ;-)

https://github.com/python/cpython/blob/main/Include/cpython/pytime.h

The _datetime module doesn't use _PyTime_t type but time_t to support the 
time_t full range (larger than _PyTime_t with 64-bit time_t).

I wrote an article about rounding timestamps:
https://vstinner.github.io/pytime.html

It seems like not all issues have been fixed yet :-)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44831>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to