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

Ticket #10466: date_time_xmlschema_fixes_1.9.diff

File date_time_xmlschema_fixes_1.9.diff, 3.5 kB (added by chuyeow, 9 months ago)
  • test/core_ext/date_time_ext_test.rb

    old new  
    3232    assert_equal DateTime.new(2005, 2, 21), DateTime.new(2005, 2, 21).to_datetime 
    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 
    3837    assert_equal Time.utc_time(2039, 2, 21, 10, 11, 12), DateTime.new(2039, 2, 21, 10, 11, 12, 0, 0).to_time 
     
    200199  end 
    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) 
    208207    assert_match(/^2080-02-28T15:15:10-06:?00$/, DateTime.civil(2080, 2, 28, 15, 15, 10, -0.25).xmlschema) 
  • lib/active_support/core_ext/date_time/conversions.rb

    old new  
    99            alias_method :to_s, :to_formatted_s 
    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 
    1418 
     
    3842        # If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time 
    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 
    4448        def to_datetime 
    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 
    5357  end 
  • lib/active_support/core_ext/date/conversions.rb

    old new  
    2020 
    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 
    2528