This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients SilentGhost, acucci, belopolsky, berker.peksag, cvrebert, ezio.melotti, gvanrossum, jerry.elmore, lemburg, martin.panter, matrixise, terry.reedy, tim.peters, vstinner
Date 2016-03-01.21:47:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1456868828.04.0.881651006597.issue19475@psf.upfronthosting.co.za>
In-reply-to
Content
> But what should we do in your opinion?

Use ROUND_FLOOR rounding method.

time.time(), datetime.datetime.now(), etc. round the current time using the ROUND_FLOOR rounding method.

Only datetime.datetime.fromtimestamp() uses ROUND_HALF_EVEN, but it's more an exception than the rule: this function uses a float as input. To be consistent, we must use the same rounding method than other Python functions taking float as parameter, like round(), so use ROUND_HALF_EVEN.

So I suggest to also use ROUND_FLOOR for .isoformat().

Hopefully, we don't have to discuss about the exact rounding method for negative numbers, since the minimum datetime object is datetime.datetime(1, 1, 1) which is "positive" ;-)

You have a similar rounding question for file timestamps. Depending on the file system, you may have a resolution of 2 seconds (FAT), 1 second (ext3) or 1 nanosecond (ext4). But Linux syscalls accept subsecond resolution. The Linux kernel uses ROUND_FLOOR rounding method if I recall correctly. I guess that it's a requirement for makefiles. If you already experimented a system clock slew, you may understand me :-)


> For full seconds, truncation will add an error of +/- 1 second,
> whereas rounding only adds +/- 0.5 seconds. This is what convinced
> me to use rounding instead of truncation.

What is truncation? Is it the ROUND_FLOOR (towards -inf) rounding method? Like math.floor(float).

Python int(float) uses ROUND_DOWN (towards zero) which is different than ROUND_FLOOR, but only different for negative numbers. int(-0.9) returns 0, whereas math.floor(-0.9) returns -1.

I guess that "rounding" means ROUND_HALF_EVEN here? The funny "Round to nearest with ties going to nearest even integer" rounding method. Like round(float).
History
Date User Action Args
2016-03-01 21:47:08vstinnersetrecipients: + vstinner, lemburg, gvanrossum, tim.peters, terry.reedy, belopolsky, ezio.melotti, cvrebert, SilentGhost, berker.peksag, martin.panter, matrixise, jerry.elmore, acucci
2016-03-01 21:47:08vstinnersetmessageid: <1456868828.04.0.881651006597.issue19475@psf.upfronthosting.co.za>
2016-03-01 21:47:08vstinnerlinkissue19475 messages
2016-03-01 21:47:07vstinnercreate