Module: Mongoid::Extensions::Date::ClassMethods
- Defined in:
- lib/mongoid/extensions/date.rb
Instance Method Summary collapse
-
#demongoize(object) ⇒ Date
Convert the object from its mongo friendly ruby type to this type.
-
#mongoize(object) ⇒ Time
Turn the object from the ruby type we deal with to a Mongo friendly type.
Instance Method Details
#demongoize(object) ⇒ Date
Convert the object from its mongo friendly ruby type to this type.
47 48 49 |
# File 'lib/mongoid/extensions/date.rb', line 47 def demongoize(object) ::Date.new(object.year, object.month, object.day) if object end |
#mongoize(object) ⇒ Time
Turn the object from the ruby type we deal with to a Mongo friendly type.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mongoid/extensions/date.rb', line 60 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 |