Sha256: 1fafeb04e3944308788649e23c9d434861155104a9151dc1a2d2dcdbd3445b9b

Contents?: true

Size: 1.05 KB

Versions: 56

Compression:

Stored size: 1.05 KB

Contents

module ActiveSupport #:nodoc:
  module CoreExtensions #:nodoc:
    module Date #:nodoc:
      # Getting dates in different convenient string representations and other objects
      module Conversions
        DATE_FORMATS = {
          :short => "%e %b",
          :long  => "%B %e, %Y",
          :db => "%Y-%m-%d"
        }

        def self.included(klass) #:nodoc:
          klass.send(:alias_method, :to_default_s, :to_s)
          klass.send(:alias_method, :to_s, :to_formatted_s)
        end

        def to_formatted_s(format = :default)
          DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s
        end

        # To be able to keep Dates and Times interchangeable on conversions
        def to_date
          self
        end

        def to_time(form = :local)
          if respond_to?(:hour)
            ::Time.send(form, year, month, day, hour, min, sec)
          else
            ::Time.send(form, year, month, day)
          end
        end

        def xmlschema
          to_time.xmlschema
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
backlog-0.0.0 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.0.1 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.0.2 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.0.5 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.0.4 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.1.0 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.1.1 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.1.2 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.2.0 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.2.1 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.0 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.2 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.1 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.3 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.4 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.5 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.6 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.7 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.8 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb
backlog-0.3.9 vendor/rails/activesupport/lib/active_support/core_ext/date/conversions.rb