-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: BSON
Currently Mongoid implements special handling for serialization of ActiveSupport::TimeWithZone objects to BSON, since this class does not derive from Time. Driver and bson library itself don't handle these objects specially. As a result, when querying data on a driver collection in a mongoid app (vs using a model) the query built is not correct.
good_time = Time.now bad_time = Time.now.in_time_zone("Pacific Time (US & Canada)") User.collection.find(:u_at => {:$lt => bad_time}).to_a.length # this query will be wrong # the problem is that: good_time.to_bson != bad_time.to_bson
A patch has been proposed in https://github.com/mongodb/bson-ruby/pull/104, however it couples bson-ruby too tightly to AS. My preference is to have a separate file for AS integration which Mongoid would require. The test suite in bson-ruby should also be run separately with and without having AS loaded.
Lastly, code handling AS::TWZ in Mongoid should be examined to see if any of it should be moved to bson-ruby/driver or deleted, if driver/bson-ruby handle the serialization.
- is depended on by
-
RUBY-1464 Time offset ignored in aggregation queries when using ActiveSupport::TimeWithZone
- Closed
- is related to
-
MONGOID-4658 Fix & integration test querying by TimeWithZone via driver
- Closed