From faa72ee66d1ff5e995297e905059c0074581873f Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 14 Aug 2024 09:38:59 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"Calculate=20travel=5Foffset=20to=20al?= =?UTF-8?q?ign=20with=20the=20precision=20of=20argument=20to=20Ti=E2=80=A6?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e05c2c07ba4ec93e84dcf228b4c617f98ad2489d. --- History.md | 2 -- lib/timecop/time_stack_item.rb | 2 +- test/time_stack_item_test.rb | 18 ------------------ 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/History.md b/History.md index 4f2eaf2..91442a9 100644 --- a/History.md +++ b/History.md @@ -2,8 +2,6 @@ ## Unreleased -- Calculate travel_offset to align with the precision of argument to Timecop.travel ([#421](https://github.com/travisjeffery/timecop/pull/421)) - ## v0.9.10 - Make Process.clock_gettime configurable and turned off by default (for backwards compatability) ([#427](https://github.com/travisjeffery/timecop/pull/427)) diff --git a/lib/timecop/time_stack_item.rb b/lib/timecop/time_stack_item.rb index 82373d6..ef49150 100644 --- a/lib/timecop/time_stack_item.rb +++ b/lib/timecop/time_stack_item.rb @@ -157,7 +157,7 @@ def parse_time(*args) end def compute_travel_offset - time.to_r - Time.now_without_mock_time.to_r + time - Time.now_without_mock_time end def times_are_equal_within_epsilon t1, t2, epsilon_in_seconds diff --git a/test/time_stack_item_test.rb b/test/time_stack_item_test.rb index e65bbeb..ed5ccf7 100644 --- a/test/time_stack_item_test.rb +++ b/test/time_stack_item_test.rb @@ -296,22 +296,4 @@ def test_datetime_timezones assert_equal dt, now, "#{dt.to_f}, #{now.to_f}" end end - - def test_travel_offset_aligns_to_clock - t = Time.now - stack_item = Timecop::TimeStackItem.new(:travel, t) - travel_offset_denom = stack_item.travel_offset.to_r.denominator - clock_resolution = Process.clock_getres(:CLOCK_REALTIME, :hertz) - assert_equal 0, clock_resolution.modulo(travel_offset_denom), - "travel offset precision (#{travel_offset_denom}) does not align with clock resolution (#{clock_resolution})" - end - - def test_travel_offset_aligns_to_travel_time - t = Time.now + 0.001_002_003_004 - stack_item = Timecop::TimeStackItem.new(:travel, t) - travel_offset_denom = stack_item.travel_offset.to_r.denominator - travel_time_denom = t.to_r.denominator - assert_equal 0, travel_time_denom.modulo(travel_offset_denom), - "travel offset precision (#{travel_offset_denom}) does not align with travel time precision (#{travel_time_denom})" - end end