Sha256: 81d6338283388086573c18c18f216f525b24785cc1575f8330656dfb36696ce2

Contents?: true

Size: 1.83 KB

Versions: 27

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

module Mongoid
  module Extensions
    module TimeWithZone

      # Mongoizes an ActiveSupport::TimeWithZone into a time.
      #
      # TimeWithZone always mongoize into TimeWithZone instances
      # (which are themselves).
      #
      # @return [ ActiveSupport::TimeWithZone ] self.
      #
      # @since 3.0.0
      def __mongoize_time__
        self
      end

      # 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

27 entries across 27 versions & 2 rubygems

Version Path
mongoid-7.3.5 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.3.4 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.1.11 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.2.6 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.3.3 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.3.2 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.2.5 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.1.10 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.1.9 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.2.4 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.3.1 lib/mongoid/extensions/time_with_zone.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/mongoid-7.1.7/lib/mongoid/extensions/time_with_zone.rb
mongoid-7.3.0 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.2.3 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.1.8 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.2.2 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.2.1 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.1.7 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.2.0 lib/mongoid/extensions/time_with_zone.rb
mongoid-7.1.6 lib/mongoid/extensions/time_with_zone.rb