Skip to content

Conversation

@bsharpe
Copy link
Contributor

@bsharpe bsharpe commented Jun 3, 2016

Description

In ruby/rails -- storing a Time.now.end_of_day in rethink, always returns the next day

> d = Date.today
> d.to_time
=> 2016-06-03 00:00 +0000
> d.to_time.end_of_day
=> 2016-06-03 23:59 +0000
> d.to_time.end_of_day.to_i
=> 1464998399
> d.to_time.end_of_day.to_r
=> (1464998399999999999/1000000000)

> d.to_time.end_of_day.to_f
=> 1464998400.0     <--- The Problem
> ((d.to_time.end_of_day.to_r  * 1000).to_i / 1000.0)  <--- The Fix
=> 1464998399.999

Due to a rounding error with .to_f

The fix ensures that the Time is truncated to milliseconds with no rounding error.

@mlucy mlucy added this to the 2.3.x milestone Jun 3, 2016
@mlucy mlucy added the Ruby label Jun 3, 2016
@mlucy
Copy link
Member

mlucy commented Jun 3, 2016

Thanks for the PR @bsharpe !

@danielmewes -- this looks good to me.

@danielmewes
Copy link
Member

Merging. We'll include this in the next Ruby driver release, probably together with RethinkDB 2.3.5.

@danielmewes danielmewes merged commit 8702cca into rethinkdb:next Jul 20, 2016
danielmewes pushed a commit that referenced this pull request Jul 20, 2016
* fix for rounding error with ruby times

* truncate time instead of rounding
@danielmewes
Copy link
Member

Cherry-picked into v2.3.x via 06ec038

Thanks again for the PR @bsharpe .

@danielmewes danielmewes modified the milestones: 2.3.x, 2.3.5 Jul 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants