lib/timecop/time_stack_item.rb in timecop-0.5.1 vs lib/timecop/time_stack_item.rb in timecop-0.5.2
- old
+ new
@@ -4,13 +4,15 @@
# movements on a simple stack.
class TimeStackItem #:nodoc:
attr_reader :mock_type
def initialize(mock_type, *args)
- raise "Unknown mock_type #{mock_type}" unless [:freeze, :travel].include?(mock_type)
+ raise "Unknown mock_type #{mock_type}" unless [:freeze, :travel, :scale].include?(mock_type)
+ @scaling_factor = args.shift if mock_type == :scale
@mock_type = mock_type
@time = parse_time(*args)
+ @time_was = Time.now_without_mock_time
@travel_offset = compute_travel_offset
@dst_adjustment = compute_dst_adjustment(@time)
end
def year
@@ -42,16 +44,26 @@
end
def travel_offset
@travel_offset
end
+
+ def scaling_factor
+ @scaling_factor
+ end
def time(time_klass=Time) #:nodoc:
if travel_offset.nil?
time_klass.at( @time.to_f )
- else
+ elsif scaling_factor.nil?
time_klass.at( ( Time.now_without_mock_time + travel_offset ).to_f )
+ else
+ time_klass.at( scaled_time )
end
+ end
+
+ def scaled_time
+ (@time + (Time.now_without_mock_time - @time_was) * scaling_factor).to_f
end
def date(date_klass=Date)
date_klass.jd(time.__send__(:to_date).jd)
end