[前][次][番号順一覧][スレッド一覧]

ruby-changes:23072

From: nobu <ko1@a...>
Date: Sat, 24 Mar 2012 22:22:33 +0900 (JST)
Subject: [ruby-changes:23072] nobu:r35122 (trunk): * time.c (time_init_1): Time.new will accept seconds as string or

nobu	2012-03-24 22:22:22 +0900 (Sat, 24 Mar 2012)

  New Revision: 35122

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35122

  Log:
    * time.c (time_init_1): Time.new will accept seconds as string or
      int.  [ruby-core:43569][Bug #6193]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_time.rb
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 35121)
+++ time.c	(revision 35122)
@@ -845,6 +845,7 @@
 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 @@
 
     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;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35121)
+++ ChangeLog	(revision 35122)
@@ -1,3 +1,8 @@
+Sat Mar 24 22:22:18 2012  Sambasiva Rao Suda  <sambasivarao@g...>
+
+	* 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@i...>
 
 	* transcode.c (documentation for str_encode): Explain
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 35121)
+++ test/ruby/test_time.rb	(revision 35122)
@@ -744,4 +744,11 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]