Sha256: c91065fd99d35970e82063178cfc7a5ecece7a0c9a4d0dbb4b87b71a29198ec0

Contents?: true

Size: 1.46 KB

Versions: 27

Compression:

Stored size: 1.46 KB

Contents

# encoding: utf-8
module Origin
  module Extensions

    # This module contains additional date behaviour.
    module Date

      # Evolve the date into a mongo friendly time, UTC midnight.
      #
      # @example Evolve the date.
      #   date.__evolve_date__
      #
      # @return [ Time ] The date as a UTC time at midnight.
      #
      # @since 1.0.0
      def __evolve_date__
        ::Time.utc(year, month, day, 0, 0, 0, 0)
      end

      # Evolve the date into a time, which is always in the local timezone.
      #
      # @example Evolve the date.
      #   date.__evolve_time__
      #
      # @return [ Time ] The date as a local time.
      #
      # @since 1.0.0
      def __evolve_time__
        ::Time.local(year, month, day)
      end

      module ClassMethods

        # Evolve the object to an date.
        #
        # @example Evolve dates.
        #   Date.evolve(Date.new(1990, 1, 1))
        #
        # @example Evolve string dates.
        #   Date.evolve("1990-1-1")
        #
        # @example Evolve date ranges.
        #   Date.evolve(Date.new(1990, 1, 1)..Date.new(1990, 1, 4))
        #
        # @param [ Object ] object The object to evolve.
        #
        # @return [ Time ] The evolved date.
        #
        # @since 1.0.0
        def evolve(object)
          object.__evolve_date__
        end
      end
    end
  end
end

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

Version data entries

27 entries across 26 versions & 4 rubygems

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