aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-09 05:55:29 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-09 05:55:29 +0000
commit1089c35f5adb75610404bdacfaa48778b06b1d82 (patch)
treea45dc490a6586017ef47cbe089935d56f39e0c5d /test
parent49f12b65021362648fbd49c6c86be41500445ae2 (diff)
downloadruby-1089c35f5adb75610404bdacfaa48778b06b1d82.tar.gz
Time.parse based from non-Time object
* lib/time.rb (Time.make_time): as the document states, the second argument of `Time.parse` may be a non-`Time` object which does not have `getlocal` method, assume it is in the local time in the case. based on the patch by nkmrya (Yasuhiro Nakamura) at [ruby-core:68775]. [ruby-core:68775] [Bug #11037] Co-authored-by: nkmrya (Yasuhiro Nakamura) <yasuhiro6194@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/test_time.rb19
1 files changed, 19 insertions, 0 deletions
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