Module: Mongoid::Extensions::Time::ClassMethods
- Defined in:
- lib/mongoid/extensions/time.rb
Instance Method Summary collapse
-
#configured ⇒ Object
Get the configured time to use when converting - either the time zone or the time.
-
#demongoize(object) ⇒ Time
Convert the object from it’s 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
#configured ⇒ Object
Get the configured time to use when converting - either the time zone or the time.
30 31 32 |
# File 'lib/mongoid/extensions/time.rb', line 30 def configured Mongoid.use_activesupport_time_zone? ? (::Time.zone || ::Time) : ::Time end |
#demongoize(object) ⇒ Time
Convert the object from it’s mongo friendly ruby type to this type.
44 45 46 47 48 49 50 51 |
# File 'lib/mongoid/extensions/time.rb', line 44 def demongoize(object) return nil if object.blank? object = object.getlocal unless Mongoid::Config.use_utc? if Mongoid::Config.use_activesupport_time_zone? object = object.in_time_zone(Mongoid.time_zone) end object end |
#mongoize(object) ⇒ Time
Turn the object from the ruby type we deal with to a Mongo friendly type.
64 65 66 67 68 69 70 71 |
# File 'lib/mongoid/extensions/time.rb', line 64 def mongoize(object) return nil if object.blank? begin ::Time.at(object.__mongoize_time__.to_f).utc rescue ArgumentError raise Errors::InvalidTime.new(object) end end |