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

Changeset 8398

Show
Ignore:
Timestamp:
12/15/07 02:27:29 (5 months ago)
Author:
bitsweat
Message:

Ruby 1.9 compat: normalize date and time xmlschema to match Ruby's formatting [chuyeow]

Files:

Legend:

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

    r8076 r8398  
    1010            alias_method :default_inspect, :inspect 
    1111            alias_method :inspect, :readable_inspect 
     12 
     13            # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows 
     14            # DateTimes outside the range of what can be created with Time. 
     15            remove_method :to_time if base.instance_methods.include?(:to_time) 
    1216          end 
    1317        end 
     
    3943        def to_time 
    4044          self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self 
    41         end         
     45        end 
    4246 
    4347        # To be able to keep Times, Dates and DateTimes interchangeable on conversions 
     
    4549          self 
    4650        end 
    47          
     51 
    4852        def xmlschema 
    49           strftime("%Y-%m-%dT%H:%M:%S#{offset == 0 ? 'Z' : '%Z'}") 
    50         end 
     53          strftime("%Y-%m-%dT%H:%M:%S%Z") 
     54        end if RUBY_VERSION < '1.9' 
    5155      end 
    5256    end 
  • trunk/activesupport/lib/active_support/core_ext/date/conversions.rb

    r8279 r8398  
    2121            # Ruby 1.9 has Date#to_time which converts to localtime only. 
    2222            remove_method :to_time if base.instance_methods.include?(:to_time) 
     23 
     24            # Ruby 1.9 has Date#xmlschema which converts to a string without the time component. 
     25            remove_method :xmlschema if base.instance_methods.include?(:xmlschema) 
    2326          end 
    2427        end 
  • trunk/activesupport/test/core_ext/date_time_ext_test.rb

    r8198 r8398  
    3333  end 
    3434 
    35   # FIXME: ruby 1.9 compat 
    3635  def test_to_time 
    3736    assert_equal Time.utc(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, 0, 0).to_time 
     
    201200 
    202201  def test_xmlschema 
    203     assert_equal '1880-02-28T15:15:10Z', DateTime.civil(1880, 2, 28, 15, 15, 10).xmlschema 
    204     assert_equal '1980-02-28T15:15:10Z', DateTime.civil(1980, 2, 28, 15, 15, 10).xmlschema 
    205     assert_equal '2080-02-28T15:15:10Z', DateTime.civil(2080, 2, 28, 15, 15, 10).xmlschema 
     202    assert_match(/^1880-02-28T15:15:10\+00:?00$/, DateTime.civil(1880, 2, 28, 15, 15, 10).xmlschema) 
     203    assert_match(/^1980-02-28T15:15:10\+00:?00$/, DateTime.civil(1980, 2, 28, 15, 15, 10).xmlschema) 
     204    assert_match(/^2080-02-28T15:15:10\+00:?00$/, DateTime.civil(2080, 2, 28, 15, 15, 10).xmlschema) 
    206205    assert_match(/^1880-02-28T15:15:10-06:?00$/, DateTime.civil(1880, 2, 28, 15, 15, 10, -0.25).xmlschema) 
    207206    assert_match(/^1980-02-28T15:15:10-06:?00$/, DateTime.civil(1980, 2, 28, 15, 15, 10, -0.25).xmlschema)