diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-25 21:43:19 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-25 21:43:19 +0000 |
commit | ad4f1fd630dbeeb66b9cde0979518b4af96201ad (patch) | |
tree | 07c7f9265cac455eb587da68a68bea01e825edd2 /activesupport/lib/active_support/core_ext/date | |
parent | c4a31560bd686cbd16b4af20e764a9a0660cd170 (diff) | |
download | rails-ad4f1fd630dbeeb66b9cde0979518b4af96201ad.tar.gz rails-ad4f1fd630dbeeb66b9cde0979518b4af96201ad.tar.bz2 rails-ad4f1fd630dbeeb66b9cde0979518b4af96201ad.zip |
Date, Time, and DateTime support formatting blocks in addition to strftime strings. Introduce :long_ordinal format, e.g. 'February 21st, 2005'. Closes #8191.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6844 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date/conversions.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 8f48ccacde..01dd8461e4 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -4,9 +4,10 @@ module ActiveSupport #:nodoc: # Getting dates in different convenient string representations and other objects module Conversions DATE_FORMATS = { - :short => "%e %b", - :long => "%B %e, %Y", - :db => "%Y-%m-%d" + :short => "%e %b", + :long => "%B %e, %Y", + :db => "%Y-%m-%d", + :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") } # => "April 25th, 2007" } def self.included(klass) #:nodoc: @@ -15,7 +16,15 @@ module ActiveSupport #:nodoc: end def to_formatted_s(format = :default) - DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s + if formatter = DATE_FORMATS[format] + if formatter.respond_to?(:call) + formatter.call(self).to_s + else + strftime(formatter).strip + end + else + to_default_s + end end # To be able to keep Dates and Times interchangeable on conversions |