module Mongoid::TimeWithNamedZone
Object that stores time and tz information as embedded object transparently works with AS:TwZ, supports mongoid serialization
Constants
- VERSION
Public Class Methods
demongoize(object)
click to toggle source
Convert the object from its mongo friendly ruby type to this type
# File lib/mongoid/time_with_named_zone.rb, line 11 def demongoize(object) return nil unless object.is_a? Hash object = object.to_h.symbolize_keys! return nil unless object[:time] && object[:zone] object[:time].in_time_zone(object[:zone]) end
mongoize(object)
click to toggle source
Turn the object from the ruby type we deal with to a Mongo friendly type
# File lib/mongoid/time_with_named_zone.rb, line 19 def mongoize(object) case object when ActiveSupport::TimeWithZone { time: object.utc.mongoize, zone: object.time_zone.name.mongoize } when Time || DateTime { time: object.utc.mongoize, zone: 'UTC'.mongoize } when Date { time: object.mongoize, zone: 'UTC'.mongoize } when Hash { time: object[:time], zone: object[:zone] } end end
Also aliased as: evolve