Module: ActiveSupport::CoreExtensions::Time::Conversions
- Included in:
- Time
- Defined in:
- lib/active_support/core_ext/time/conversions.rb
Overview
Getting times in different convenient string representations and other objects
Constant Summary collapse
- DATE_FORMATS =
{ :db => "%Y-%m-%d %H:%M:%S", :short => "%e %b %H:%M", :long => "%B %e, %Y %H:%M" }
Class Method Summary collapse
Instance Method Summary collapse
- #to_date ⇒ Object
- #to_formatted_s(format = :default) ⇒ Object
-
#to_time ⇒ Object
To be able to keep Dates and Times interchangeable on conversions.
Class Method Details
.append_features(klass) ⇒ Object
14 15 16 17 18 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 14 def self.append_features(klass) super 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
24 25 26 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 24 def to_date ::Date.new(year, month, day) end |
#to_formatted_s(format = :default) ⇒ Object
20 21 22 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 20 def to_formatted_s(format = :default) DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s end |
#to_time ⇒ Object
To be able to keep Dates and Times interchangeable on conversions
29 30 31 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 29 def to_time self end |