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

Changeset 9137

Show
Ignore:
Timestamp:
03/29/08 21:23:10 (5 months ago)
Author:
bitsweat
Message:

Play nice with 1.9's DateTime#to_s

Files:

Legend:

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

    r9042 r9137  
    66        def self.included(base) #:nodoc: 
    77          base.class_eval do 
     8            alias_method :to_default_s, :to_s if instance_methods.include?(:to_s) 
    89            alias_method :to_s, :to_formatted_s 
    910            alias_method :default_inspect, :inspect 
     
    1213            # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows 
    1314            # DateTimes outside the range of what can be created with Time. 
    14             remove_method :to_time if base.instance_methods.include?(:to_time) 
     15            remove_method :to_time if instance_methods.include?(:to_time) 
    1516          end 
    1617        end 
  • trunk/activesupport/test/core_ext/date_time_ext_test.rb

    r9042 r9137  
    44  def test_to_s 
    55    datetime = DateTime.new(2005, 2, 21, 14, 30, 0, 0) 
    6     assert_match(/^2005-02-21T14:30:00(Z|\+00:00)$/,  datetime.to_s) 
    76    assert_equal "2005-02-21 14:30:00",               datetime.to_s(:db) 
    87    assert_equal "14:30",                             datetime.to_s(:time) 
     
    1110    assert_equal "Mon, 21 Feb 2005 14:30:00 +0000",   datetime.to_s(:rfc822) 
    1211    assert_equal "February 21st, 2005 14:30",         datetime.to_s(:long_ordinal) 
     12    assert_match(/^2005-02-21T14:30:00(Z|\+00:00)$/,  datetime.to_s) 
    1313  end 
    1414