-
Notifications
You must be signed in to change notification settings - Fork 110
Precision loss for NSDate #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes, when I call
We delegate to |
We are responsible for passing a value with a certain precision expectation though. In order for the back and forth conversion to have no information loss beyond the precision we have to round. |
Actually, while implementing a PR for this I've noticed in your stress test that due to |
In what date ranges did you observe the loss of precision? If it's only dates outside the range most useful in practice (±100 years from now), maybe it's still worth extending our precision limit. |
It was quite large around 1000 years before/after 1970 (e.g. year 800 or 3300). I haven't checked if there's an acceptable range though. |
Turns out, a roundtrip in the near times only loses 0.5 microseconds of precision, whereas at the far ends of the supported range, we lose 10 microseconds. It is a lot, but much less than the microsecond precision loss that happens when an NSDate is formatted (which led us to this implementation in the first place). Fixes #427
When converting an
Instant
toNSDate
and back toInstant
the value is rounded to milliseconds. However, when testing I see microsecond precision after callingtoNSDate()
and even when usingNSDate.addTimeInterval()
and also when instantiating a newNSDate()
object. This doesn’t match what the docstring claims.You probably only refer to the NSDateFormatter having a bug and dropping to millisecond precision? The rest of the NSDate API seems to work fine with microsecond precision though, so it makes no sense to be lossy in Kotlin.
At the Kotlin level, the loss in precision only happens in the
NSDate.toKotlinInstant()
extension function. Could you please fix this function to preserve microsecond precision instead of millisecond precision - consistent with the test result?Also, the
toNSDate()
function doesn't round the last (microsecond) digit, which is probably a bug.The text was updated successfully, but these errors were encountered: