Module: ActiveSupport::CoreExtensions::Date::Conversions

Included in:
Date
Defined in:
lib/active_support/core_ext/date/conversions.rb

Overview

Getting dates in different convenient string representations and other objects

Constant Summary collapse

DATE_FORMATS =
{
  :short => "%e %b",
  :long  => "%B %e, %Y"
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(klass) ⇒ Object

:nodoc:



11
12
13
14
15
# File 'lib/active_support/core_ext/date/conversions.rb', line 11

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

Instance Method Details

#to_dateObject

To be able to keep Dates and Times interchangeable on conversions



22
23
24
# File 'lib/active_support/core_ext/date/conversions.rb', line 22

def to_date
  self
end

#to_formatted_s(format = :default) ⇒ Object



17
18
19
# File 'lib/active_support/core_ext/date/conversions.rb', line 17

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

#to_time(form = :local) ⇒ Object



26
27
28
# File 'lib/active_support/core_ext/date/conversions.rb', line 26

def to_time(form = :local)
  ::Time.send(form, year, month, day)
end