Sha256: 135801696fb341ea08a15646d93d6e06265df7b921ddb1992487131b9880964f

Contents?: true

Size: 1.49 KB

Versions: 68

Compression:

Stored size: 1.49 KB

Contents

# encoding: utf-8
module Mongoid
  module Extensions
    module TimeWithZone

      # 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.
      #
      # @since 3.0.0
      def mongoize
        ::ActiveSupport::TimeWithZone.mongoize(self)
      end

      module ClassMethods

        # Convert the object from its mongo friendly ruby type to this type.
        #
        # @example Demongoize the object.
        #   TimeWithZone.demongoize(object)
        #
        # @param [ Time ] object The time from Mongo.
        #
        # @return [ TimeWithZone ] The object as a date.
        #
        # @since 3.0.0
        def demongoize(object)
          return nil if object.blank?
          ::Time.demongoize(object).in_time_zone
        end

        # Turn the object from the ruby type we deal with to a Mongo friendly
        # type.
        #
        # @example Mongoize the object.
        #   TimeWithZone.mongoize("2012-1-1")
        #
        # @param [ Object ] object The object to convert.
        #
        # @return [ Time ] The object mongoized.
        #
        # @since 3.0.0
        def mongoize(object)
          ::Time.mongoize(object)
        end
      end
    end
  end
end

::ActiveSupport::TimeWithZone.__send__(:include, Mongoid::Extensions::TimeWithZone)
::ActiveSupport::TimeWithZone.extend(Mongoid::Extensions::TimeWithZone::ClassMethods)

Version data entries

68 entries across 63 versions & 3 rubygems

Version Path
mongoid-7.0.13 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.12 lib/mongoid/extensions/time_with_zone.rb
mongoid-6.4.8 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.11 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.10 lib/mongoid/extensions/time_with_zone.rb
mongoid-6.4.7 lib/mongoid/extensions/time_with_zone.rb
mongoid-6.4.5 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.8 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.7 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.6 lib/mongoid/extensions/time_with_zone.rb
mongoid-5.4.1 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.5 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.4 lib/mongoid/extensions/time_with_zone.rb
mongoid-6.4.4 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.3 lib/mongoid/extensions/time_with_zone.rb
mongoid-6.4.2 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.2 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.0.1 lib/mongoid/extensions/time_with_zone.rb
mongoid-6.4.1 lib/mongoid/extensions/time_with_zone.rb
mongoid-5.4.0 lib/mongoid/extensions/time_with_zone.rb