module Mongoid::Extensions::TimeWithZone

Adds type-casting behavior to ActiveSupport::TimeWithZone class.

Public Instance Methods

__mongoize_time__() click to toggle source

Mongoizes an ActiveSupport::TimeWithZone into a time.

TimeWithZone always mongoize into TimeWithZone instances (which are themselves).

@return [ ActiveSupport::TimeWithZone ] self.

# File lib/mongoid/extensions/time_with_zone.rb, line 16
def __mongoize_time__
  self
end
_bson_to_i() click to toggle source

This code is copied from Time class extension in bson-ruby gem. It should be removed from here when the minimum BSON version is 5+. See jira.mongodb.org/browse/MONGOID-5491.

Calls superclass method
# File lib/mongoid/extensions/time_with_zone.rb, line 34
def _bson_to_i
  return super if defined?(super)
  # Workaround for JRuby's #to_i rounding negative timestamps up
  # rather than down (https://github.com/jruby/jruby/issues/6104)
  if BSON::Environment.jruby?
    (self - usec.to_r/1000000).to_i
  else
    to_i
  end
end
mongoize() click to toggle source

Turn the object from the ruby type we deal with to a Mongo friendly type.

@example Mongoize the object.

date_time.mongoize

@return [ Time ] The object mongoized.

# File lib/mongoid/extensions/time_with_zone.rb, line 27
def mongoize
  ::ActiveSupport::TimeWithZone.mongoize(self)
end