module Mongoid::Extensions::Date::ClassMethods

def demongoize(object)

Returns:
  • (Date) - The object as a date.

Parameters:
  • object (Time) -- The time from Mongo.

Other tags:
    Example: Demongoize the object. -
def demongoize(object)
  ::Date.new(object.year, object.month, object.day) if object
end

def mongoize(object)

Returns:
  • (Time) - The object mongoized.

Parameters:
  • object (Object) -- The object to mongoize.

Other tags:
    Example: Mongoize the object. -
def mongoize(object)
  unless object.blank?
    begin
      if object.is_a?(String)
        # https://jira.mongodb.org/browse/MONGOID-4460
        time = ::Time.parse(object)
      else
        time = object.__mongoize_time__
      end
      ::Time.utc(time.year, time.month, time.day)
    rescue ArgumentError
      nil
    end
  end
end