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

Changeset 8606

Show
Ignore:
Timestamp:
01/09/08 08:46:08 (1 year ago)
Author:
bitsweat
Message:

Document date and time to_formatted_s. Closes #10747 [leethal]

Files:

Legend:

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

    r8428 r8606  
    22  module CoreExtensions #:nodoc: 
    33    module DateTime #:nodoc: 
    4       # Getting datetimes in different convenient string representations and other objects 
     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) 
    526      module Conversions 
    6         def self.included(base) 
     27        def self.included(base) #:nodoc: 
    728          base.class_eval do 
    829            alias_method :to_datetime_default_s, :to_s 
  • trunk/activesupport/lib/active_support/core_ext/date/conversions.rb

    r8546 r8606  
    22  module CoreExtensions #:nodoc: 
    33    module Date #:nodoc: 
    4       # Getting dates in different convenient string representations and other objects 
     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) 
    525      module Conversions 
    626        DATE_FORMATS = { 
  • trunk/activesupport/lib/active_support/core_ext/time/conversions.rb

    r8546 r8606  
    22  module CoreExtensions #:nodoc: 
    33    module Time #:nodoc: 
    4       # Getting times in different convenient string representations and other objects 
     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) 
    525      module Conversions 
    626        DATE_FORMATS = { 
     
    1434        } 
    1535 
    16         def self.included(base) 
     36        def self.included(base) #:nodoc: 
    1737          base.class_eval do 
    1838            alias_method :to_default_s, :to_s