summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_time.rb7
-rw-r--r--time.c10
3 files changed, 14 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index a5eaca474e..8f6640002a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Mar 24 22:22:18 2012 Sambasiva Rao Suda <sambasivarao@gmail.org>
+
+ * time.c (time_init_1): Time.new will accept seconds as string or
+ int. [ruby-core:43569][Bug #6193]
+
Fri Mar 23 15:12:12 2012 Martin Duerst <duerst@it.aoyama.ac.jp>
* transcode.c (documentation for str_encode): Explain
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index cf7aad38a2..e62aaf80c8 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -744,4 +744,11 @@ class TestTime < Test::Unit::TestCase
end
assert_equal("Insecure: can't modify #{tc}", error.message, bug5036)
end
+
+ def test_sec_str
+ bug6193 = '[ruby-core:43569]'
+ t = nil
+ assert_nothing_raised(bug6193) {t = Time.new(2012, 1, 2, 3, 4, "5")}
+ assert_equal(Time.new(2012, 1, 2, 3, 4, 5), t, bug6193)
+ end
end
diff --git a/time.c b/time.c
index 0de32aed5f..7ec27a5693 100644
--- a/time.c
+++ b/time.c
@@ -845,6 +845,7 @@ static VALUE obj2vint(VALUE obj);
static int month_arg(VALUE arg);
static void validate_utc_offset(VALUE utc_offset);
static void validate_vtm(struct vtm *vtm);
+static int obj2subsecx(VALUE obj, VALUE *subsecx);
static VALUE time_gmtime(VALUE);
static VALUE time_localtime(VALUE);
@@ -2156,15 +2157,8 @@ time_init_1(int argc, VALUE *argv, VALUE time)
vtm.min = NIL_P(v[4]) ? 0 : obj2int(v[4]);
- vtm.sec = 0;
vtm.subsecx = INT2FIX(0);
- if (!NIL_P(v[5])) {
- VALUE sec = num_exact(v[5]);
- VALUE subsec;
- divmodv(sec, INT2FIX(1), &sec, &subsec);
- vtm.sec = NUM2INT(sec);
- vtm.subsecx = w2v(rb_time_magnify(v2w(subsec)));
- }
+ vtm.sec = NIL_P(v[5]) ? 0 : obj2subsecx(v[5], &vtm.subsecx);
vtm.isdst = -1;
vtm.utc_offset = Qnil;