aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb8
-rw-r--r--activesupport/test/core_ext/date_time_ext_test.rb20
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb8
3 files changed, 30 insertions, 6 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 3ef4744c44..05835a5fed 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -174,9 +174,13 @@ class DateExtCalculationsTest < Test::Unit::TestCase
def test_xmlschema
with_timezone 'US/Eastern' do
- assert_match(/^1880-06-28T00:00:00-04:?00$/, Date.new(1880, 6, 28).xmlschema)
+ assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema)
assert_match(/^1980-06-28T00:00:00-04:?00$/, Date.new(1980, 6, 28).xmlschema)
- assert_match(/^2080-06-28T00:00:00-04:?00$/, Date.new(2080, 6, 28).xmlschema)
+ # these tests are only of interest on platforms where older dates #to_time fail over to DateTime
+ if ::DateTime === Date.new(1880, 6, 28).to_time
+ assert_match(/^1880-02-28T00:00:00-05:?00$/, Date.new(1880, 2, 28).xmlschema)
+ assert_match(/^1880-06-28T00:00:00-05:?00$/, Date.new(1880, 6, 28).xmlschema) # DateTimes aren't aware of DST rules
+ end
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 f4d5427d0f..0f2c788926 100644
--- a/activesupport/test/core_ext/date_time_ext_test.rb
+++ b/activesupport/test/core_ext/date_time_ext_test.rb
@@ -35,8 +35,9 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase
# FIXME: ruby 1.9 compat
def test_to_time
assert_equal Time.utc(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, 0, 0).to_time
- assert_equal Time.local(2005, 2, 21, 10, 11, 12), DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24), 0).to_time
assert_equal Time.utc_time(2039, 2, 21, 10, 11, 12), DateTime.new(2039, 2, 21, 10, 11, 12, 0, 0).to_time
+ # DateTimes with offsets other than 0 are returned unaltered
+ assert_equal DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24)), DateTime.new(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).to_time
end
def test_seconds_since_midnight
@@ -211,4 +212,21 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase
def test_acts_like_time
assert DateTime.new.acts_like_time?
end
+
+ def test_local_offset
+ with_timezone 'US/Eastern' do
+ assert_equal Rational(-5, 24), DateTime.local_offset
+ end
+ with_timezone 'US/Central' do
+ assert_equal Rational(-6, 24), DateTime.local_offset
+ 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/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 9965e2574a..8ead0d7fe6 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -312,7 +312,9 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal "17:44", time.to_s(:time)
assert_equal "February 21, 2005 17:44", time.to_s(:long)
assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal)
- assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822)
+ with_timezone "UTC" do
+ assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822)
+ end
end
def test_custom_date_format
@@ -387,8 +389,8 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
def test_local_time
assert_equal Time.local_time(2005, 2, 21, 17, 44, 30), Time.local(2005, 2, 21, 17, 44, 30)
- assert_equal Time.local_time(2039, 2, 21, 17, 44, 30), DateTime.civil(2039, 2, 21, 17, 44, 30, DateTime.now.offset, 0)
- assert_equal Time.local_time(1901, 2, 21, 17, 44, 30), DateTime.civil(1901, 2, 21, 17, 44, 30, DateTime.now.offset, 0)
+ assert_equal Time.local_time(2039, 2, 21, 17, 44, 30), DateTime.civil(2039, 2, 21, 17, 44, 30, DateTime.local_offset, 0)
+ assert_equal Time.local_time(1901, 2, 21, 17, 44, 30), DateTime.civil(1901, 2, 21, 17, 44, 30, DateTime.local_offset, 0)
end
def test_next_month_on_31st