aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG5
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb4
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb16
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb9
4 files changed, 32 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index ffeeadfa00..d8fe2ce1f9 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,3 +1,8 @@
+*SVN*
+
+* Fixed Date#xmlschema for dates outside the range of what can be created with Time #9744 [gbuesing]
+
+
*2.0.0 [Preview Release]* (September 29th, 2007)
* Fixed that La Paz was included in -25200 and -14400 offsets when it should only be in -14400 #9735 [bermi]
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 4739e3fb6d..776f1806f9 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -45,6 +45,10 @@ module ActiveSupport #:nodoc:
def to_datetime
self
end
+
+ def xmlschema
+ strftime("%Y-%m-%dT%H:%M:%S#{offset == 0 ? 'Z' : '%Z'}")
+ end
end
end
end
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 97b637f974..70f7cb0df7 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -162,4 +162,20 @@ class DateExtCalculationsTest < Test::Unit::TestCase
def test_end_of_day
assert_equal Time.local(2005,2,21,23,59,59), Date.new(2005,2,21).end_of_day
end
+
+ def test_xmlschema
+ with_timezone 'US/Eastern' do
+ assert_equal '1880-06-28T00:00:00-04:00', Date.new(1880, 6, 28).xmlschema
+ assert_equal '1980-06-28T00:00:00-04:00', Date.new(1980, 6, 28).xmlschema
+ assert_equal '2080-06-28T00:00:00-04:00', Date.new(2080, 6, 28).xmlschema
+ end
+ end
+
+ protected
+ def with_timezone(new_tz = 'US/Eastern')
+ old_tz, ENV['TZ'] = ENV['TZ'], new_tz
+ yield
+ ensure
+ old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
+ end
end
diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb
index 204e8cd676..6984481a71 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -182,8 +182,13 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase
assert_equal DateTime.civil(2004, 2, 29), DateTime.civil(2004, 3, 31).last_month
end
- def test_xmlschema_is_available
- assert_nothing_raised { DateTime.now.xmlschema }
+ def test_xmlschema
+ assert_equal '1880-02-28T15:15:10Z', DateTime.civil(1880, 2, 28, 15, 15, 10).xmlschema
+ assert_equal '1980-02-28T15:15:10Z', DateTime.civil(1980, 2, 28, 15, 15, 10).xmlschema
+ assert_equal '2080-02-28T15:15:10Z', DateTime.civil(2080, 2, 28, 15, 15, 10).xmlschema
+ assert_equal '1880-02-28T15:15:10-06:00', DateTime.civil(1880, 2, 28, 15, 15, 10, -0.25).xmlschema
+ assert_equal '1980-02-28T15:15:10-06:00', DateTime.civil(1980, 2, 28, 15, 15, 10, -0.25).xmlschema
+ assert_equal '2080-02-28T15:15:10-06:00', DateTime.civil(2080, 2, 28, 15, 15, 10, -0.25).xmlschema
end
def test_acts_like_time