diff --git a/lib/time.rb b/lib/time.rb index 0bfd9a9a45..a2ada7728b 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -267,7 +267,7 @@ class Time return make_time(date, year, nil, mon, day, hour, min, sec, sec_fraction, zone, now) end - if now + if now and now.respond_to?(:getlocal) if off now = now.getlocal(off) if now.utc_offset != off else diff --git a/test/test_time.rb b/test/test_time.rb index 29fad6fbf4..138766443b 100644 --- a/test/test_time.rb +++ b/test/test_time.rb @@ -523,4 +523,23 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc: define_method(test) {__send__(sub, :xmlschema)} define_method(test.sub(/xmlschema/, 'iso8601')) {__send__(sub, :iso8601)} end + + def test_parse_with_various_object + d = Date.new(2010, 10, 28) + dt = DateTime.new(2010, 10, 28) + md = MyDate.new(10, 28, 2010) + + t = Time.local(2010, 10, 28, 21, 26, 00) + assert_equal(t, Time.parse("21:26", d)) + assert_equal(t, Time.parse("21:26", dt)) + assert_equal(t, Time.parse("21:26", md)) + end + + class MyDate + attr_reader :mon, :day, :year + + def initialize(mon, day, year) + @mon, @day, @year = mon, day, year + end + end end