Fixes Time objects to have same time as when saved in mongodb #455

wants to merge 5 commits into from

2 participants


New pull request because of incorrect pushes in the previous pull request.
One line for both REE and 1.9.3, instead of version dependent solution. Basically same as #443


Travis fails on compound keys. Time tests and extensions passes.

MongoMapper member

iso8601 is ridiculously slow. Given that the core type conversions are core to read/write performance, I'd be really hesitant to endorse that solution.

Additionally, using #round explicitly breaks this test, which was added in response to a bugfix. If we're to preserve this test, then any millisecond-rounding feature must perform a floor rather than a round.

I'd propose just:

-          at(time.to_f).utc if time # ensure milliseconds are preserved with to_f (issue #308)
+          at((time.to_f * 1000.0).to_i / 1000.0).utc if time

This isn't as fast as #round, but it's cross-version compliant and doesn't break any tests.

@cheald cheald added a commit that closed this pull request Jul 8, 2013
@cheald cheald When performing Time#to_mongo, round times off to milliseconds and di…
…scard microseconds. Closes #455.
@cheald cheald closed this in 9b3bd27 Jul 8, 2013

Sorry about not answering before. I agree that it is slow using iso8601...

I think the pull you just did is perfect, as 1.8.x is end of life.

Initial pull request was similar to your proposal, however, it was removed as it was not 1.8.x compatible.

Discussion here, about why it was changed.

Thanks for fixing this in master 👍

I was about to go mongoid on a project, but now I got a reason to stick with MM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment