Ticket #9349: date.patch
| File date.patch, 1.5 kB (added by TomK32, 1 year ago) |
|---|
-
lib/active_support/core_ext/date/conversions.rb
old new 3 3 module Date #:nodoc: 4 4 # Getting dates in different convenient string representations and other objects 5 5 module Conversions 6 7 # A few common date formats a date can be formatted into by using to_formatted_s 8 # Examples: 9 # :short => 2 Aug 10 # :long => August 2, 2007 11 # :db => 2007-08-02 12 # :long_ordinal => August 2nd, 2007 13 # :rfc822 => 2 Aug 2007 6 14 DATE_FORMATS = { 7 15 :short => "%e %b", 8 16 :long => "%B %e, %Y", 9 17 :db => "%Y-%m-%d", 10 :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }, # => "April 25th, 2007"18 :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }, 11 19 :rfc822 => "%e %b %Y" 12 20 } 13 21 … … 18 26 klass.send(:alias_method, :inspect, :readable_inspect) 19 27 end 20 28 29 # Converts self either to one of the DATE_FORMATS or if +format+ 30 # is not included, it invokes to_default_s 21 31 def to_formatted_s(format = :default) 22 32 if formatter = DATE_FORMATS[format] 23 33 if formatter.respond_to?(:call)