diff --git a/test/test_helper.rb b/test/test_helper.rb index 61925e3a..6dab8278 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -48,7 +48,7 @@ def a_time_stack_item end def assert_date_times_equal(dt1, dt2) - assert_equal dt1, dt2, "Failed for timezone: #{ENV['TZ']}: #{dt1.to_s} not equal to #{dt2.to_s}" + assert_in_delta dt1.to_time.to_f, dt2.to_time.to_f, 0.01, "Failed for timezone: #{ENV['TZ']}: #{dt1.to_s} not equal to #{dt2.to_s}" end end diff --git a/test/time_stack_item_test.rb b/test/time_stack_item_test.rb index 3c31bdf1..4ac66852 100644 --- a/test/time_stack_item_test.rb +++ b/test/time_stack_item_test.rb @@ -113,6 +113,19 @@ def test_utc_offset_to_rational assert_equal Rational(1, 24), a_time_stack_item.send(:utc_offset_to_rational, 3600) end + def test_datetime_in_presence_of_activesupport_timezone + skip('requires ActiveSupport') unless Time.respond_to? :zone + backed_up_zone, backed_up_tzvar = Time.zone, ENV['TZ'] + + Time.zone = ENV['TZ'] = 'America/Los_Angeles' + t = DateTime.new(2001, 2, 28, 23, 59, 59.5) + tsi = Timecop::TimeStackItem.new(:freeze, t) + + assert_date_times_equal t, tsi.datetime + ensure + Time.zone, ENV['TZ'] = backed_up_zone, backed_up_tzvar + end + # Ensure DateTimes handle changing DST properly def test_datetime_for_dst_to_non_dst Timecop.freeze(DateTime.parse("2009-12-1 00:38:00 -0500"))