Changeset 8398
- Timestamp:
- 12/15/07 02:27:29 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/date_time/conversions.rb
r8076 r8398 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 … … 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 … … 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 trunk/activesupport/lib/active_support/core_ext/date/conversions.rb
r8279 r8398 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 trunk/activesupport/test/core_ext/date_time_ext_test.rb
r8198 r8398 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 … … 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)