diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-09 08:46:08 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-09 08:46:08 +0000 |
commit | c9fc4d2ca38ae917658d3abf0c9858d6ebc4d366 (patch) | |
tree | f7540d185c9bf31e193c049a13b97f55344e3276 /activesupport/lib/active_support/core_ext/date/conversions.rb | |
parent | e9b862acb02f9b6a507023e493a9abb2a2fb62da (diff) | |
download | rails-c9fc4d2ca38ae917658d3abf0c9858d6ebc4d366.tar.gz rails-c9fc4d2ca38ae917658d3abf0c9858d6ebc4d366.tar.bz2 rails-c9fc4d2ca38ae917658d3abf0c9858d6ebc4d366.zip |
Document date and time to_formatted_s. Closes #10747 [leethal]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8606 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date/conversions.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 684775c5e3..e06ca3ada5 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -1,7 +1,27 @@ module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Date #:nodoc: - # Getting dates in different convenient string representations and other objects + # Getting datetimes in different convenient string representations and other objects. + # + # == Adding your own time formats in to_formatted_s + # You can add your own time formats by merging them into the DATE_FORMATS constant. Use a string with + # Ruby's strftime formatting (http://ruby-doc.org/core/classes/Time.html#M000297), or + # pass a lambda. The lambda yields the instance to_formatted_s is called on, so that calculations + # can be performed on that instance. This is handy when Ruby's strftime formatting is insufficient. See + # the +short_ordinal+ example below. + # + # See DATE_FORMATS for the list of built-in formats, and to_formatted_s for implementation details. + # + # === Examples: + # # config/initializers/time_formats.rb + # ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!( + # :month_and_year => "%B %Y", + # :short_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}") } + # ) + # + # Calling it on a Time instance: + # + # Time.now.to_s(:short_ordinal) module Conversions DATE_FORMATS = { :short => "%e %b", |