Skip to content

Commit cc5da76

Browse files
committed
Merge pull request #215 from or-else/patch-1
A bug in conversion of milliseconds
2 parents 613a15c + 08eafb4 commit cc5da76

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pseudotypes.go

+3-2
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 != "" {

query_time_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ func (s *RethinkSuite) TestTimeTime(c *test.C) {
1818

1919
func (s *RethinkSuite) TestTimeTimeMillisecond(c *test.C) {
2020
var response time.Time
21-
res, err := Time(1986, 11, 3, 12, 30, 15.679, "Z").Run(session)
21+
res, err := Time(1986, 11, 3, 12, 30, 15.6790123, "Z").Run(session)
2222
c.Assert(err, test.IsNil)
2323

2424
err = res.One(&response)
2525
c.Assert(err, test.IsNil)
26-
c.Assert(response.Equal(time.Date(1986, 11, 3, 12, 30, 15, 679.00002*1000*1000, time.UTC)), test.Equals, true)
26+
c.Assert(response.Equal(time.Date(1986, 11, 3, 12, 30, 15, 679*1000*1000, time.UTC)), test.Equals, true)
2727
}
2828

2929
func (s *RethinkSuite) TestTimeEpochTime(c *test.C) {

0 commit comments

Comments
 (0)