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 => "%d %b %H:%M", :long => "%B %d, %Y %H:%M", :rfc822 => "%a, %d %b %Y %H:%M:%S %z" }
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
16 17 18 19 20 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 16 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
26 27 28 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 26 def to_date ::Date.new(year, month, day) end |
#to_formatted_s(format = :default) ⇒ Object
22 23 24 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 22 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
31 32 33 |
# File 'lib/active_support/core_ext/time/conversions.rb', line 31 def to_time self end |