Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up`as.ITime` should round sub-second values instead of `floor`/truncate #2870
Comments
|
Regarding the last point, yes, it's to do with negative numbers -- truncation means always bringing the number closer to 0, which in this case means rounding "up" for negative numbers:
|
|
The fix is as simple as fixing this line... I'm not immediately sold that we should change the behavior, though...
Anyway, I'll file a PR to start the discussion with a solution in hand |
|
Actually, I think internal behavior is inconsistent at the moment, IIUC:
I don't know what a |
|
Confirmed:
|
(referencing closed issue #2156 as requested by Matt)
as.ITimeconverts time strings to integers, so it makes sense that any inputs with sub-second precision would be rounded to the nearest second. Unfortunately, it always rounds down (probably just truncating the input to discard decimal values), which doesn't seem like the best option to me.The issue
For example:
This isn't just being printed that way, the integer behind the scenes agrees with the printed value:
Comparison with
chron::timesThe
chronpackage uses numeric instead of integer values, so this isn't an issue there:Comparison with
as.POSIXctas.POSIXctprints the "truncated" value, but retains the sub-second precision in the numeric value behind the scenes:Something odd I noticed with
as.POSIXctOddly,
POSIXctseems to truncate sometimes, possibly depending on timezone, and possibly something to do with negative numbers. Not sure why this is, and it's not related todata.tableat all, just something I noticed when looking at the above, so you might notice it too: