Sha256: b8a10f7c4d2fc6d2433c2d2f1e9d727def307099c55c027d0b7f232881e63353

Contents?: true

Size: 1.64 KB

Versions: 17

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module Mongoid
  class Criteria
    module Queryable
      module Extensions

        # This module contains additional time with zone behavior.
        module TimeWithZone

          # Evolve the time as a date, UTC midnight.
          #
          # @example Evolve the time to a date query format.
          #   time.__evolve_date__
          #
          # @return [ Time ] The date at midnight UTC.
          def __evolve_date__
            ::Time.utc(year, month, day, 0, 0, 0, 0)
          end

          # Evolve the time into a utc time.
          #
          # @example Evolve the time.
          #   time.__evolve_time__
          #
          # @return [ Time ] The time in UTC.
          def __evolve_time__
            utc
          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

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

Version data entries

17 entries across 17 versions & 1 rubygems

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