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

Changeset 8608

Show
Ignore:
Timestamp:
01/09/08 09:45:56 (8 months ago)
Author:
bitsweat
Message:

Simplify to_formatted_s docs. Closes #10747 [Jeremy Kemper]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb

    r8606 r8608  
    22  module CoreExtensions #:nodoc: 
    33    module DateTime #:nodoc: 
    4       # Getting datetimes in different convenient string representations and other objects. 
    5       # 
    6       # == Adding your own time formats in to_formatted_s 
    7       # You can add your own time formats by merging them into the  ::Time::Conversions::DATE_FORMATS constant. Use a string with 
    8       # Ruby's strftime formatting (http://ruby-doc.org/core/classes/Time.html#M000297), or 
    9       # pass a lambda. The lambda yields the instance to_formatted_s is called on, so that calculations 
    10       # can be performed on that instance. This is handy when Ruby's strftime formatting is insufficient. See 
    11       # the +short_ordinal+ example below. 
    12       # 
    13       # See ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS for the list of built-in formats, and 
    14       # to_formatted_s for implementation details. 
    15       # 
    16       # === Examples: 
    17       #   # config/initializers/time_formats.rb 
    18       #   ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( 
    19       #     :month_and_year => "%B %Y", 
    20       #     :short_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    21       #   ) 
    22       # 
    23       # Calling it on a Time instance: 
    24       # 
    25       #   Time.now.to_s(:short_ordinal) 
     4      # Converting datetimes to formatted strings, dates, and times. 
    265      module Conversions 
    276        def self.included(base) #:nodoc: 
     
    3716          end 
    3817        end 
    39          
    40         # Convert to a formatted string - see DATE_FORMATS for predefined formats. 
    41         # You can also add your own formats to the DATE_FORMATS constant and use them with this method. 
     18 
     19        # Convert to a formatted string. See Time::DATE_FORMATS for predefined formats. 
    4220        #  
    43         # This method is also aliased as <tt>to_s</tt>. 
     21        # This method is aliased to <tt>to_s</tt>. 
    4422        #  
    4523        # === Examples: 
     
    5331        #   datetime.to_formatted_s(:long_ordinal)  # => "December 4th, 2007 00:00" 
    5432        #   datetime.to_formatted_s(:rfc822)        # => "Tue, 04 Dec 2007 00:00:00 +0000" 
     33        # 
     34        # == Adding your own datetime formats to to_formatted_s 
     35        # DateTime formats are shared with Time. You can add your own to the 
     36        # Time::DATE_FORMATS hash. Use the format name as the hash key and 
     37        # either a strftime string or Proc instance that takes a time or 
     38        # datetime argument as the value. 
     39        # 
     40        #   # config/initializers/time_formats.rb 
     41        #   Time::DATE_FORMATS[:month_and_year] = "%B %Y" 
     42        #   Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    5543        def to_formatted_s(format = :default) 
    5644          if formatter = ::Time::DATE_FORMATS[format] 
  • trunk/activesupport/lib/active_support/core_ext/date/conversions.rb

    r8606 r8608  
    22  module CoreExtensions #:nodoc: 
    33    module Date #:nodoc: 
    4       # Getting datetimes in different convenient string representations and other objects. 
    5       # 
    6       # == Adding your own time formats in to_formatted_s 
    7       # You can add your own time formats by merging them into the DATE_FORMATS constant. Use a string with 
    8       # Ruby's strftime formatting (http://ruby-doc.org/core/classes/Time.html#M000297), or 
    9       # pass a lambda. The lambda yields the instance to_formatted_s is called on, so that calculations 
    10       # can be performed on that instance. This is handy when Ruby's strftime formatting is insufficient. See 
    11       # the +short_ordinal+ example below. 
    12       # 
    13       # See DATE_FORMATS for the list of built-in formats, and to_formatted_s for implementation details. 
    14       # 
    15       # === Examples: 
    16       #   # config/initializers/time_formats.rb 
    17       #   ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!( 
    18       #     :month_and_year => "%B %Y", 
    19       #     :short_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    20       #   ) 
    21       # 
    22       # Calling it on a Time instance: 
    23       # 
    24       #   Time.now.to_s(:short_ordinal) 
     4      # Converting dates to formatted strings, times, and datetimes. 
    255      module Conversions 
    266        DATE_FORMATS = { 
     
    4828        end 
    4929 
    50         # Convert to a formatted string - see DATE_FORMATS for predefined formats. 
    51         # You can also add your own formats to the DATE_FORMATS constant and use them with this method. 
     30        # Convert to a formatted string. See DATE_FORMATS for predefined formats. 
    5231        # 
    53         # This method is also aliased as <tt>to_s</tt>. 
     32        # This method is aliased to <tt>to_s</tt>. 
    5433        # 
    5534        # ==== Examples: 
     
    6342        #   date.to_formatted_s(:long_ordinal)  # => "November 10th, 2007" 
    6443        #   date.to_formatted_s(:rfc822)        # => "10 Nov 2007" 
     44        # 
     45        # == Adding your own time formats to to_formatted_s 
     46        # You can add your own formats to the Date::DATE_FORMATS hash. 
     47        # Use the format name as the hash key and either a strftime string 
     48        # or Proc instance that takes a date argument as the value. 
     49        # 
     50        #   # config/initializers/time_formats.rb 
     51        #   Date::DATE_FORMATS[:month_and_year] = "%B %Y" 
     52        #   Date::DATE_FORMATS[:short_ordinal] = lambda { |date| date.strftime("%B #{date.day.ordinalize}") } 
    6553        def to_formatted_s(format = :default) 
    6654          if formatter = DATE_FORMATS[format] 
  • trunk/activesupport/lib/active_support/core_ext/time/conversions.rb

    r8606 r8608  
    22  module CoreExtensions #:nodoc: 
    33    module Time #:nodoc: 
    4       # Getting times in different convenient string representations and other objects. 
    5       # 
    6       # == Adding your own time formats in to_formatted_s 
    7       # You can add your own time formats by merging them into the DATE_FORMATS constant. Use a string with 
    8       # Ruby's strftime formatting (http://ruby-doc.org/core/classes/Time.html#M000297), or 
    9       # pass a lambda. The lambda yields the instance to_formatted_s is called on, so that calculations 
    10       # can be performed on that instance. This is handy when Ruby's strftime formatting is insufficient. See 
    11       # the +short_ordinal+ example below. 
    12       # 
    13       # See ::Time::DATE_FORMATS for the list of built-in formats, and to_formatted_s for implementation details. 
    14       # 
    15       # === Examples: 
    16       #   # config/initializers/time_formats.rb 
    17       #   ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( 
    18       #     :month_and_year => "%B %Y", 
    19       #     :short_ordinal => lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    20       #   ) 
    21       # 
    22       # Calling it on a Time instance: 
    23       # 
    24       #   Time.now.to_s(:short_ordinal) 
     4      # Converting times to formatted strings, dates, and datetimes. 
    255      module Conversions 
    266        DATE_FORMATS = { 
     
    4121        end 
    4222 
    43         # Convert to a formatted string - see DATE_FORMATS for predefined formats. 
    44         # You can also add your own formats to the DATE_FORMATS constant and use them with this method. 
     23        # Convert to a formatted string. See DATE_FORMATS for builtin formats. 
    4524        # 
    46         # This method is also aliased as <tt>to_s</tt>. 
     25        # This method is aliased to <tt>to_s</tt>. 
    4726        # 
    4827        # ==== Examples: 
     
    5736        #   time.to_formatted_s(:long_ordinal)  # => "January 18th, 2007 06:10" 
    5837        #   time.to_formatted_s(:rfc822)        # => "Thu, 18 Jan 2007 06:10:17 -0600" 
     38        # 
     39        # == Adding your own time formats to to_formatted_s 
     40        # You can add your own formats to the Time::DATE_FORMATS hash. 
     41        # Use the format name as the hash key and either a strftime string 
     42        # or Proc instance that takes a time argument as the value. 
     43        # 
     44        #   # config/initializers/time_formats.rb 
     45        #   Time::DATE_FORMATS[:month_and_year] = "%B %Y" 
     46        #   Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    5947        def to_formatted_s(format = :default) 
    6048          if formatter = DATE_FORMATS[format]