Sha256: 2d91203b465e948cdb2dac5c305af64751987fa585fc19cb02175cd68f3dabfa

Contents?: true

Size: 1.41 KB

Versions: 16

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Mongoid
  class Criteria
    module Queryable
      module Extensions

        # This module contains additional datetime behavior.
        module DateTime

          # Evolve the date time into a mongo friendly UTC time.
          #
          # @example Evolve the date time.
          #   date_time.__evolve_time__
          #
          # @return [ Time ] The converted time in UTC.
          def __evolve_time__
            usec = strftime("%6N").to_f
            u = utc
            ::Time.utc(u.year, u.month, u.day, u.hour, u.min, u.sec, usec)
          end

          module ClassMethods

            # Evolve the object to an date.
            #
            # @example Evolve dates.
            #
            # @example Evolve string dates.
            #
            # @example Evolve date ranges.
            #
            # @param [ Object ] object The object to evolve.
            #
            # @return [ Time ] The evolved date time.
            def evolve(object)
              res = begin
                object.try(:__evolve_time__)
              rescue ArgumentError
                nil
              end
              res.nil? ? object : res
            end
          end
        end
      end
    end
  end
end

::DateTime.__send__(:include, Mongoid::Criteria::Queryable::Extensions::DateTime)
::DateTime.__send__(:extend, Mongoid::Criteria::Queryable::Extensions::DateTime::ClassMethods)

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mongoid-8.1.7 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.1.6 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.8 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.1.5 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.1.4 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.7 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.1.3 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.1.2 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.6 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.1.1 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.5 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.1.0 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.4 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.3 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.2 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-8.0.1 lib/mongoid/criteria/queryable/extensions/date_time.rb