Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9349: date.patch

File date.patch, 1.5 kB (added by TomK32, 1 year ago)

patch for Date/Conversions.to_formatted_s

  • lib/active_support/core_ext/date/conversions.rb

    old new  
    33    module Date #:nodoc: 
    44      # Getting dates in different convenient string representations and other objects 
    55      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 
    614        DATE_FORMATS = { 
    715          :short        => "%e %b", 
    816          :long         => "%B %e, %Y", 
    917          :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") }, 
    1119          :rfc822       => "%e %b %Y" 
    1220        } 
    1321 
     
    1826          klass.send(:alias_method, :inspect, :readable_inspect)           
    1927        end 
    2028 
     29        # Converts self either to one of the DATE_FORMATS or if +format+ 
     30        # is not included, it invokes to_default_s 
    2131        def to_formatted_s(format = :default) 
    2232          if formatter = DATE_FORMATS[format] 
    2333            if formatter.respond_to?(:call)