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

Ticket #7164: docs_for_time_conversions.diff

File docs_for_time_conversions.diff, 1.3 kB (added by rsanheim, 1 year ago)
  • core_ext/time/conversions.rb

    old new  
    1919          klass.send(:alias_method, :to_s, :to_formatted_s) 
    2020        end 
    2121         
     22        # Convert to a formatted string - see DATE_FORMATS for predefined formats. 
     23        # You can also add your own formats to the DATE_FORMATS constant and use them with this method. 
     24        # 
     25        # examples:  
     26        # 
     27        #   time = Time.now                  # => Thu Jan 18 06:10:17 CST 2007 
     28        #   time.to_formatted_s(:time)       # => "Thu Jan 18 06:10:17 CST 2007" 
     29        #   time.to_formatted_s(:db)         # => "2007-01-18 06:10:17" 
     30        #   time.to_formatted_s(:short)      # => "18 Jan 06:10"</tt> 
     31        #   time.to_formatted_s(:long)       # => "January 18, 2007 06:10" 
     32        #   time.to_formatted_s(:rfc822)     # => "Thu, 18 Jan 2007 06:10:17 -0600" 
    2233        def to_formatted_s(format = :default) 
    2334          DATE_FORMATS[format] ? strftime(DATE_FORMATS[format]).strip : to_default_s           
    2435        end 
    2536 
     37        # Convert a Time object to a Date - this drops hour, minute, and second precision. 
    2638        def to_date 
    2739          ::Date.new(year, month, day) 
    2840        end