diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-12-17 00:18:27 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-12-17 00:18:27 +0000 |
commit | be0c45365c912240b4979150f8c1284916007bca (patch) | |
tree | e87622bd7a8a60262559b5903ed745a8a83ab6e2 | |
parent | dcc1549512b2b20889c6bcd7f91485a002286d5c (diff) | |
download | rails-be0c45365c912240b4979150f8c1284916007bca.tar.gz rails-be0c45365c912240b4979150f8c1284916007bca.tar.bz2 rails-be0c45365c912240b4979150f8c1284916007bca.zip |
Docfix (closes #10369) [revans]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8428 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/conversions.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb index 52e6b6bdea..8ea8679b42 100644 --- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb @@ -15,7 +15,22 @@ module ActiveSupport #:nodoc: remove_method :to_time if base.instance_methods.include?(:to_time) end end - + + # Convert to a formatted string - see DATE_FORMATS for predefined formats. + # You can also add your own formats to the DATE_FORMATS constant and use them with this method. + # + # This method is also aliased as <tt>to_s</tt>. + # + # === Examples: + # datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000 + # + # datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00" + # datetime.to_s(:db) # => "2007-12-04 00:00:00" + # datetime.to_s(:number) # => "20071204000000" + # datetime.to_formatted_s(:short) # => "04 Dec 00:00" + # datetime.to_formatted_s(:long) # => "December 04, 2007 00:00" + # datetime.to_formatted_s(:long_ordinal) # => "December 4th, 2007 00:00" + # datetime.to_formatted_s(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000" def to_formatted_s(format = :default) if formatter = ::Time::DATE_FORMATS[format] if formatter.respond_to?(:call) @@ -49,6 +64,7 @@ module ActiveSupport #:nodoc: self end + # Converts datetime to an appropriate format for use in XML def xmlschema strftime("%Y-%m-%dT%H:%M:%S%Z") end if RUBY_VERSION < '1.9' |