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
-
.included(klass) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#to_date ⇒ Object
To be able to keep Dates and Times interchangeable on conversions.
- #to_formatted_s(format = :default) ⇒ Object
- #to_time(form = :local) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
:nodoc:
11 12 13 14 |
# File 'lib/active_support/core_ext/date/conversions.rb', line 11 def self.included(klass) #:nodoc: klass.send(:alias_method, :to_default_s, :to_s) klass.send(:alias_method, :to_s, :to_formatted_s) end |
Instance Method Details
#to_date ⇒ Object
To be able to keep Dates and Times interchangeable on conversions
21 22 23 |
# File 'lib/active_support/core_ext/date/conversions.rb', line 21 def to_date self end |
#to_formatted_s(format = :default) ⇒ Object
16 17 18 |
# File 'lib/active_support/core_ext/date/conversions.rb', line 16 def to_formatted_s(format = :default) DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s end |