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

Changeset 8609

Show
Ignore:
Timestamp:
01/09/08 09:49:12 (6 months ago)
Author:
bitsweat
Message:

Merge [8608] to stable: simplify to_formatted_s docs. References #10747.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2-0-stable/activesupport/lib/active_support/core_ext/date_time/conversions.rb

    r8607 r8609  
    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] 
  • branches/2-0-stable/activesupport/lib/active_support/core_ext/date/conversions.rb

    r8607 r8609  
    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 = { 
     
    4727        end 
    4828 
    49         # Convert to a formatted string - see DATE_FORMATS for predefined formats. 
    50         # You can also add your own formats to the DATE_FORMATS constant and use them with this method. 
     29        # Convert to a formatted string. See DATE_FORMATS for predefined formats. 
    5130        # 
    52         # This method is also aliased as <tt>to_s</tt>. 
     31        # This method is aliased to <tt>to_s</tt>. 
    5332        # 
    5433        # ==== Examples: 
     
    6241        #   date.to_formatted_s(:long_ordinal)  # => "November 10th, 2007" 
    6342        #   date.to_formatted_s(:rfc822)        # => "10 Nov 2007" 
     43        # 
     44        # == Adding your own time formats to to_formatted_s 
     45        # You can add your own formats to the Date::DATE_FORMATS hash. 
     46        # Use the format name as the hash key and either a strftime string 
     47        # or Proc instance that takes a date argument as the value. 
     48        # 
     49        #   # config/initializers/time_formats.rb 
     50        #   Date::DATE_FORMATS[:month_and_year] = "%B %Y" 
     51        #   Date::DATE_FORMATS[:short_ordinal] = lambda { |date| date.strftime("%B #{date.day.ordinalize}") } 
    6452        def to_formatted_s(format = :default) 
    6553          if formatter = DATE_FORMATS[format] 
  • branches/2-0-stable/activesupport/lib/active_support/core_ext/time/conversions.rb

    r8607 r8609  
    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 = { 
     
    4020        end 
    4121 
    42         # Convert to a formatted string - see DATE_FORMATS for predefined formats. 
    43         # You can also add your own formats to the DATE_FORMATS constant and use them with this method. 
     22        # Convert to a formatted string. See DATE_FORMATS for builtin formats. 
    4423        # 
    45         # This method is also aliased as <tt>to_s</tt>. 
     24        # This method is aliased to <tt>to_s</tt>. 
    4625        # 
    4726        # ==== Examples: 
     
    5635        #   time.to_formatted_s(:long_ordinal)  # => "January 18th, 2007 06:10" 
    5736        #   time.to_formatted_s(:rfc822)        # => "Thu, 18 Jan 2007 06:10:17 -0600" 
     37        # 
     38        # == Adding your own time formats to to_formatted_s 
     39        # You can add your own formats to the Time::DATE_FORMATS hash. 
     40        # Use the format name as the hash key and either a strftime string 
     41        # or Proc instance that takes a time argument as the value. 
     42        # 
     43        #   # config/initializers/time_formats.rb 
     44        #   Time::DATE_FORMATS[:month_and_year] = "%B %Y" 
     45        #   Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") } 
    5846        def to_formatted_s(format = :default) 
    5947          if formatter = DATE_FORMATS[format]