Message261080
> 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). |
|
Date |
User |
Action |
Args |
2016-03-01 21:47:08 | vstinner | set | recipients:
+ 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:08 | vstinner | set | messageid: <1456868828.04.0.881651006597.issue19475@psf.upfronthosting.co.za> |
2016-03-01 21:47:08 | vstinner | link | issue19475 messages |
2016-03-01 21:47:07 | vstinner | create | |
|