summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 02:18:37 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-21 02:18:37 +0000
commit8bb93fc8ae53a541be4aa0c3223f1e505b913386 (patch)
tree010c77cba4a995de1311cf4c2799ba89b7f0cb1f /ext
parente41fde8b776e299342543a85f315646a25bec194 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/win32ole/win32ole.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index a99bff2..72b67fb 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.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)
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)
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)
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));
}