Changeset 8606
- Timestamp:
- 01/09/08 08:46:08 (6 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb
r8428 r8606 2 2 module CoreExtensions #:nodoc: 3 3 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) 5 26 module Conversions 6 def self.included(base) 27 def self.included(base) #:nodoc: 7 28 base.class_eval do 8 29 alias_method :to_datetime_default_s, :to_s trunk/activesupport/lib/active_support/core_ext/date/conversions.rb
r8546 r8606 2 2 module CoreExtensions #:nodoc: 3 3 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) 5 25 module Conversions 6 26 DATE_FORMATS = { trunk/activesupport/lib/active_support/core_ext/time/conversions.rb
r8546 r8606 2 2 module CoreExtensions #:nodoc: 3 3 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) 5 25 module Conversions 6 26 DATE_FORMATS = { … … 14 34 } 15 35 16 def self.included(base) 36 def self.included(base) #:nodoc: 17 37 base.class_eval do 18 38 alias_method :to_default_s, :to_s