Sha256: f6f52f24e7b51ccb07ef842b6a82dcbc7b3dbb27fd3ae5e511c0590116597f04

Contents?: true

Size: 1.43 KB

Versions: 38

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8
module Mongoid
  class Criteria
    module Queryable
      module Extensions

        # This module contains additional datetime behaviour.
        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.
          #
          # @since 1.0.0
          def __evolve_time__
            usec = strftime("%6N").to_f
            if utc?
              ::Time.utc(year, month, day, hour, min, sec, usec)
            else
              ::Time.local(year, month, day, hour, min, sec, usec).utc
            end
          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.
            #
            # @since 1.0.0
            def evolve(object)
              object.__evolve_time__
            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

38 entries across 36 versions & 2 rubygems

Version Path
mongoid-7.0.13 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.12 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-6.4.8 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.11 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.10 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-6.4.7 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-6.4.5 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.8 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.7 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.6 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.5 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.4 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-6.4.4 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.3 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-6.4.2 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.2 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.1 lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-6.4.1 lib/mongoid/criteria/queryable/extensions/date_time.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/lib/mongoid/criteria/queryable/extensions/date_time.rb
mongoid-7.0.0 lib/mongoid/criteria/queryable/extensions/date_time.rb