diff --git a/lib/delorean.rb b/lib/delorean.rb index f1b8068..758ca0d 100644 --- a/lib/delorean.rb +++ b/lib/delorean.rb @@ -38,7 +38,7 @@ def reset def mock_current_time(time, options={}) time = Chronic.parse(time, options) if time.is_a?(String) - time = Time.local(time.year, time.month, time.day) if time.is_a?(Date) + time = Time.local(time.year, time.month, time.day) if time.is_a?(Date) && !time.is_a?(DateTime) time_travel_offsets.push Time.now - time end diff --git a/spec/delorean_spec.rb b/spec/delorean_spec.rb index 4f93fa0..35608fe 100644 --- a/spec/delorean_spec.rb +++ b/spec/delorean_spec.rb @@ -41,6 +41,13 @@ 'Back in good old 1955.' end.should eql 'Back in good old 1955.' end + + it "should work with DateTime" do + datetime = DateTime.strptime("2011-05-25 18:00", "%Y-%m-%d %H:%M") + Delorean.time_travel_to(datetime) do + Time.now.should be_close(datetime, 1) + end + end end describe "back_to_the_present" do