Rounding error in datetime conversion

Hello everyone,

I just stumbled upon a slight rounding error when working with the function absolutedate_to_datetime() (in The error is only of one millisecond but caused some sanity checks in the code I am using to fail, which can be quite annoying.

For instance, when converting 31.526168 seconds to seconds and microseconds, the function returns 31 seconds and 526167 micreseconds (because in Python, 31.526168 - 31 = 31.52616799999… and the function truncates the decimal part instead of rounding it off)

A suggestion would be to replace line 121 of :

microseconds = int(1000000.0 * (seconds - math.floor(seconds)))

by something like

microsecond = int(round(second - int(second), 6))

Best regards,

Good idea @abulte,

Could you please open an issue on the Python wrapper issue tracker ?

Thanks for noticing this, it should definitely round correctly, but looking at the source of datetime, microseconds can also be float (as can seconds), would there be any preference to keep microseconds as an int in the conversion to python datetime?