-
-
Notifications
You must be signed in to change notification settings - Fork 178
A bug in conversion of milliseconds #215
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
Conversation
Rethink stores time as a floating point number with precision to milliseconds. Go's native time has precision to nanoseconds. The gorethink's conversion of time from float64 milliseconds to time.Time creates artifacts in microseconds and nanoseconds. With the current code every time.Time fetched from RethinkDB it must be rounded to milliseconds if consistency of stored vs retrieved value is important. It makes sense to do correct rounding in the driver. The fix ensures that the time is consistent.
The failing test makes no sense to me. It asserts that |
The failing test is due to the hacky way the test was originally implemented https://github.com/dancannon/gorethink/blob/master/query_time_test.go#L26. With your fix this is no longer needed so the test could probably be changed to: c.Assert(response.Equal(time.Date(1986, 11, 3, 12, 30, 15, 679*1000*1000, time.UTC)), test.Equals, true) Would it be possible for you to include that in your PR? |
Fixing failing test
I made a change to the call to Time to assert that precision beyond milliseconds is correctly stripped. |
I stumbled over this too. For what it's worth, I rounded the time value with time.Round(time.Millisecond) in my code. Your changes look good though. |
What do you think @or-else? |
Actually that was my first attempt: |
Ok makes sense, one last question (and this is just me being slow) why are you adding 0.5 before rounding? |
It ensures correct rounding, math.Floor rounds down. See here: |
Also see discussion here: golang/go#4594 |
A bug in conversion of milliseconds
Merged, thanks again for both the PR and for dealing with all my questions! |
Rethink stores time as a floating point number with precision to milliseconds. Go's native time has precision to nanoseconds. The gorethink's conversion of time from float64 milliseconds to time.Time creates artifacts in microseconds and nanoseconds. With the current code every time.Time fetched from RethinkDB must be rounded to milliseconds if consistency of stored vs retrieved value is important. It makes sense to do correct rounding in the driver. The fix ensures that the time is consistent.