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 32 32 assert_equal DateTime.new(2005, 2, 21), DateTime.new(2005, 2, 21).to_datetime 33 33 end 34 34 35 # FIXME: ruby 1.9 compat36 35 def test_to_time 37 36 assert_equal Time.utc(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, 0, 0).to_time 38 37 assert_equal Time.utc_time(2039, 2, 21, 10, 11, 12), DateTime.new(2039, 2, 21, 10, 11, 12, 0, 0).to_time … … 200 199 end 201 200 202 201 def test_xmlschema 203 assert_ equal '1880-02-28T15:15:10Z', DateTime.civil(1880, 2, 28, 15, 15, 10).xmlschema204 assert_ equal '1980-02-28T15:15:10Z', DateTime.civil(1980, 2, 28, 15, 15, 10).xmlschema205 assert_ equal '2080-02-28T15:15:10Z', DateTime.civil(2080, 2, 28, 15, 15, 10).xmlschema202 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) 206 205 assert_match(/^1880-02-28T15:15:10-06:?00$/, DateTime.civil(1880, 2, 28, 15, 15, 10, -0.25).xmlschema) 207 206 assert_match(/^1980-02-28T15:15:10-06:?00$/, DateTime.civil(1980, 2, 28, 15, 15, 10, -0.25).xmlschema) 208 207 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 9 9 alias_method :to_s, :to_formatted_s 10 10 alias_method :default_inspect, :inspect 11 11 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) 12 16 end 13 17 end 14 18 … … 38 42 # 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 39 43 def to_time 40 44 self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self 41 end 45 end 42 46 43 47 # To be able to keep Times, Dates and DateTimes interchangeable on conversions 44 48 def to_datetime 45 49 self 46 50 end 47 51 48 52 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' 51 55 end 52 56 end 53 57 end -
lib/active_support/core_ext/date/conversions.rb
old new 20 20 21 21 # Ruby 1.9 has Date#to_time which converts to localtime only. 22 22 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) 23 26 end 24 27 end 25 28