Permalink
Browse files

have to calculate current time when the actual and computed times are…

… different for time zones (fix #63)
  • Loading branch information...
travisjeffery committed Jan 9, 2013
1 parent 68ec6ad commit f580feeece49a919f9ab4b80c4c2f85def61345d
Showing with 14 additions and 2 deletions.
  1. +3 −1 lib/timecop/time_stack_item.rb
  2. +1 −1 lib/timecop/version.rb
  3. +10 −0 test/time_stack_item_test.rb
@@ -52,7 +52,9 @@ def scaling_factor
def time(time_klass = Time) #:nodoc:
begin
- time = time_klass.at(@time)
+ actual_time = time_klass.at(@time)
+ calculated_time = time_klass.at(@time.to_f)
+ time = times_are_equal_within_epsilon(actual_time, calculated_time, 1) ? actual_time : calculated_time
rescue
time = time_klass.at(@time.to_f)
end
View
@@ -1,3 +1,3 @@
class Timecop
- VERSION = "0.5.8"
+ VERSION = "0.5.9"
end
@@ -244,4 +244,14 @@ def test_nsecs_are_set
assert_equal time, Time.now
assert_equal time.nsec, Time.now.nsec if (Time.now.respond_to?(:nsec))
end
+
+ def test_time_with_different_timezone
+ require 'active_support/all'
+
+ Time.zone = "Tokyo"
+ t = Time.now
+ Timecop.freeze(t) do
+ assert_times_effectively_equal t, Time.now
+ end
+ end
end

0 comments on commit f580fee

Please sign in to comment.