Skip to content

Commit 738b991

Browse files
committed
A bug in conversion of milliseconds
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.
1 parent cff081d commit 738b991

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pseudotypes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ func recursivelyConvertPseudotype(obj interface{}, opts map[string]interface{})
125125

126126
func reqlTimeToNativeTime(timestamp float64, timezone string) (time.Time, error) {
127127
sec, ms := math.Modf(timestamp)
128-
129-
t := time.Unix(int64(sec), int64(ms*1000*1000*1000))
128+
129+
// Convert to native time rounding to milliseconds
130+
t := time.Unix(int64(sec), int64(math.Floor(ms*1000+0.5))*1000*1000)
130131

131132
// Caclulate the timezone
132133
if timezone != "" {

0 commit comments

Comments
 (0)