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

ruby-changes:35576

From: suke <ko1@a...>
Date: Sun, 21 Sep 2014 11:18:44 +0900 (JST)
Subject: [ruby-changes:35576] suke:r47658 (trunk): ext/win32ole/win32ole.c (rbtime2vtdate, vtdate2rbtime): fix

suke	2014-09-21 11:18:37 +0900 (Sun, 21 Sep 2014)

  New Revision: 47658

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

  Log:
    ext/win32ole/win32ole.c (rbtime2vtdate, vtdate2rbtime): fix
    the bug in conversion of milliseconds. [Bug #10258]
    
    test/win32ole/test_win32ole_variant.rb
    (test_conversion_dbl2date_with_msec,
    test_conversion_time2date_with_msec): use assert_in_delta instead
    of assert_equal to treat an acceptable error range.

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
    trunk/test/win32ole/test_win32ole_variant.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47657)
+++ ChangeLog	(revision 47658)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Sep 21 11:16:56 2014  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c (rbtime2vtdate, vtdate2rbtime): fix
+	  the bug in conversion of milliseconds. [Bug #10258]
+
+	* test/win32ole/test_win32ole_variant.rb
+	  (test_conversion_dbl2date_with_msec,
+	   test_conversion_time2date_with_msec): use assert_in_delta instead
+	   of assert_equal to treat an acceptable error range.
+
 Sun Sep 21 11:03:32 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* signal.c (ruby_signal): although "EINVAL from sigaction(2) is
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 47657)
+++ ext/win32ole/win32ole.c	(revision 47658)
@@ -26,7 +26,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L26
 const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00, 0xC0, 0x4F, 0x8F, 0x5D, 0x9A}};
 #endif
 
-#define WIN32OLE_VERSION "1.8.2"
+#define WIN32OLE_VERSION "1.8.3"
 
 typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
     (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -408,14 +408,13 @@ rbtime2vtdate(VALUE tmobj) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L408
     double t;
     double nsec;
 
-    memset(&st, 0, sizeof(SYSTEMTIME));
     st.wYear = FIX2INT(rb_funcall(tmobj, rb_intern("year"), 0));
     st.wMonth = FIX2INT(rb_funcall(tmobj, rb_intern("month"), 0));
     st.wDay = FIX2INT(rb_funcall(tmobj, rb_intern("mday"), 0));
     st.wHour = FIX2INT(rb_funcall(tmobj, rb_intern("hour"), 0));
     st.wMinute = FIX2INT(rb_funcall(tmobj, rb_intern("min"), 0));
     st.wSecond = FIX2INT(rb_funcall(tmobj, rb_intern("sec"), 0));
-    st.wMilliseconds = FIX2INT(rb_funcall(tmobj, rb_intern("nsec"), 0)) / 1000000;
+    st.wMilliseconds = 0;
     SystemTimeToVariantTime(&st, &t);
 
     /*
@@ -436,6 +435,7 @@ vtdate2rbtime(double date) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L435
     SYSTEMTIME st;
     VALUE v;
     double msec;
+    double sec;
     VariantTimeToSystemTime(date, &st);
     v = rb_funcall(rb_cTime, rb_intern("new"), 6,
 		      INT2FIX(st.wYear),
@@ -444,19 +444,26 @@ vtdate2rbtime(double date) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L444
 		      INT2FIX(st.wHour),
 		      INT2FIX(st.wMinute),
 		      INT2FIX(st.wSecond));
+    st.wYear = FIX2INT(rb_funcall(v, rb_intern("year"), 0));
+    st.wMonth = FIX2INT(rb_funcall(v, rb_intern("month"), 0));
+    st.wDay = FIX2INT(rb_funcall(v, rb_intern("mday"), 0));
+    st.wHour = FIX2INT(rb_funcall(v, rb_intern("hour"), 0));
+    st.wMinute = FIX2INT(rb_funcall(v, rb_intern("min"), 0));
+    st.wSecond = FIX2INT(rb_funcall(v, rb_intern("sec"), 0));
+    st.wMilliseconds = 0;
+    SystemTimeToVariantTime(&st, &sec);
     /*
      * Unfortunately VariantTimeToSystemTime always ignores the
      * wMilliseconds of SYSTEMTIME struct(The wMilliseconds is 0).
      * So, we need to calculate milliseconds by ourselves.
      */
-    msec = fabs(date);
-    msec -= floor(date);
+    msec = date - sec;
     msec *= 24 * 60;
     msec -= floor(msec);
     msec *= 60;
-    msec -= st.wSecond;
-    msec = round(msec * 1000);
-    msec /= 1000;
+    if (msec >= 59) {
+        msec -= 60;
+    }
     if (msec != 0) {
         return rb_funcall(v, rb_intern("+"), 1, rb_float_new(msec));
     }
Index: test/win32ole/test_win32ole_variant.rb
===================================================================
--- test/win32ole/test_win32ole_variant.rb	(revision 47657)
+++ test/win32ole/test_win32ole_variant.rb	(revision 47658)
@@ -393,7 +393,7 @@ if defined?(WIN32OLE_VARIANT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_variant.rb#L393
       obj = WIN32OLE_VARIANT.new(41878.524268391200167, WIN32OLE::VARIANT::VT_DATE)
       t = obj.value
       assert_equal("2014-08-27 12:34:56", t.strftime('%Y-%m-%d %H:%M:%S'))
-      assert_equal(789, (t.nsec / 1000000).round)
+      assert_in_delta(0.789, t.nsec / 1000000000.0, 0.001)
     end
 
     def test_conversion_time2date_with_msec
@@ -401,12 +401,12 @@ if defined?(WIN32OLE_VARIANT) https://github.com/ruby/ruby/blob/trunk/test/win32ole/test_win32ole_variant.rb#L401
       t0 += 0.789
       t1 = WIN32OLE_VARIANT.new(t0).value
       assert_equal("2014-08-27 12:34:56", t1.strftime('%Y-%m-%d %H:%M:%S'))
-      assert_equal(789, (t1.nsec / 1000000).round)
+      assert_in_delta(0.789, t1.nsec / 1000000000.0, 0.001)
 
       t0 = Time.now
       t1 = WIN32OLE_VARIANT.new(t0).value
       assert_equal(t0.strftime('%Y-%m-%d %H:%M:%S'), t1.strftime('%Y-%m-%d %H:%M:%S'))
-      assert_equal(t0.nsec.round(-6), t1.nsec.round(-6))
+      assert_in_delta(t0.nsec/1000000000.0, t1.nsec / 1000000000.0, 0.001)
     end
 
     # this test failed because of VariantTimeToSystemTime

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

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