Skip to content

Commit

Permalink
have to calculate current time when the actual and computed times are…
Browse files Browse the repository at this point in the history
… different for time zones (fix travisjeffery#63)
  • Loading branch information
Travis Jeffery committed Jan 9, 2013
1 parent 68ec6ad commit f580fee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/timecop/time_stack_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/timecop/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Timecop
VERSION = "0.5.8"
VERSION = "0.5.9"
end
10 changes: 10 additions & 0 deletions test/time_stack_item_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.