From ef7b9bf382a8e6efa472e197b8b2f8dab48cba43 Mon Sep 17 00:00:00 2001 From: suke Date: Wed, 27 Aug 2014 10:57:28 +0000 Subject: * ext/win32ole/win32ole.c (vtdate2rbtime): try to convert millisecond of VT_DATE VARIANT to nsec of Time object. * test/win32ole/test_win32ole_variant.rb (test_conversion_dbl2date_with_msec): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47297 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/win32ole/win32ole.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'ext') diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 5b08d8e990..b5f25565ff 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -26,7 +26,7 @@ const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00, 0xC0, 0x4F, 0x8F, 0x5D, 0x9A}}; #endif -#define WIN32OLE_VERSION "1.7.8" +#define WIN32OLE_VERSION "1.7.9" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -405,7 +405,7 @@ static double rbtime2vtdate(VALUE tmobj) { SYSTEMTIME st; - double t = 0; + double t; 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)); @@ -423,8 +423,8 @@ vtdate2rbtime(double date) { SYSTEMTIME st; VALUE v; + double msec; VariantTimeToSystemTime(date, &st); - v = rb_funcall(rb_cTime, rb_intern("new"), 6, INT2FIX(st.wYear), INT2FIX(st.wMonth), @@ -432,8 +432,21 @@ vtdate2rbtime(double date) INT2FIX(st.wHour), INT2FIX(st.wMinute), INT2FIX(st.wSecond)); - if (st.wMilliseconds > 0) { - return rb_funcall(v, rb_intern("+"), 1, rb_float_new((double)(st.wMilliseconds / 1000.0))); + /* + * 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 *= 24 * 60; + msec -= floor(msec); + msec *= 60; + msec -= st.wSecond; + msec = round(msec * 1000); + msec /= 1000; + if (msec != 0) { + return rb_funcall(v, rb_intern("+"), 1, rb_float_new(msec)); } return v; } -- cgit v1.2.3