Sha256: d0ad552f0cdeb2de3588bd68b45b6d01e8ffed64b55f2a29d2b2e27ec0d17c65

Contents?: true

Size: 1.18 KB

Versions: 14

Compression:

Stored size: 1.18 KB

Contents

# encoding: utf-8
module Origin
  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

::DateTime.__send__(:include, Origin::Extensions::DateTime)
::DateTime.__send__(:extend, Origin::Extensions::DateTime::ClassMethods)

Version data entries

14 entries across 13 versions & 4 rubygems

Version Path
origin-2.3.1 lib/origin/extensions/date_time.rb
origin-2.3.0 lib/origin/extensions/date_time.rb
origin-2.2.2 lib/origin/extensions/date_time.rb
origin-2.2.1 lib/origin/extensions/date_time.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/origin-2.2.0/lib/origin/extensions/date_time.rb
origin-2.2.0 lib/origin/extensions/date_time.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/origin-2.1.1/lib/origin/extensions/date_time.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/origin-2.1.1/lib/origin/extensions/date_time.rb
origin-2.1.1 lib/origin/extensions/date_time.rb
origin-2.1.0 lib/origin/extensions/date_time.rb
origin-2.0.0 lib/origin/extensions/date_time.rb
origin-1.1.0 lib/origin/extensions/date_time.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/origin-1.0.11/lib/origin/extensions/date_time.rb
origin-1.0.11 lib/origin/extensions/date_time.rb