mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/win32ole/win32ole.c (rbtime2vtdate): try to convert millisecond
of Time object to millisecond of VT_DATE VARIANT. * test/win32ole/test_win32ole_variant.rb (test_conversion_time2date_with_msec): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8bd2d31d45
commit
c5487618f5
3 changed files with 34 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Mon Sep 1 20:11:02 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||||
|
|
||||||
|
* ext/win32ole/win32ole.c (rbtime2vtdate): try to convert millisecond
|
||||||
|
of Time object to millisecond of VT_DATE VARIANT.
|
||||||
|
* test/win32ole/test_win32ole_variant.rb
|
||||||
|
(test_conversion_time2date_with_msec): ditto.
|
||||||
|
|
||||||
Sun Aug 31 16:58:49 2014 Tanaka Akira <akr@fsij.org>
|
Sun Aug 31 16:58:49 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* lib/benchmark.rb: Fix a syntax error.
|
* lib/benchmark.rb: Fix a syntax error.
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00, 0xC0, 0x4F, 0x8F, 0x5D, 0x9A}};
|
const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00, 0xC0, 0x4F, 0x8F, 0x5D, 0x9A}};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define WIN32OLE_VERSION "1.7.9"
|
#define WIN32OLE_VERSION "1.8.0"
|
||||||
|
|
||||||
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
|
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
|
||||||
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
|
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
|
||||||
|
@ -406,6 +406,8 @@ rbtime2vtdate(VALUE tmobj)
|
||||||
{
|
{
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
double t;
|
double t;
|
||||||
|
double nsec;
|
||||||
|
|
||||||
memset(&st, 0, sizeof(SYSTEMTIME));
|
memset(&st, 0, sizeof(SYSTEMTIME));
|
||||||
st.wYear = FIX2INT(rb_funcall(tmobj, rb_intern("year"), 0));
|
st.wYear = FIX2INT(rb_funcall(tmobj, rb_intern("year"), 0));
|
||||||
st.wMonth = FIX2INT(rb_funcall(tmobj, rb_intern("month"), 0));
|
st.wMonth = FIX2INT(rb_funcall(tmobj, rb_intern("month"), 0));
|
||||||
|
@ -415,7 +417,17 @@ rbtime2vtdate(VALUE tmobj)
|
||||||
st.wSecond = FIX2INT(rb_funcall(tmobj, rb_intern("sec"), 0));
|
st.wSecond = FIX2INT(rb_funcall(tmobj, rb_intern("sec"), 0));
|
||||||
st.wMilliseconds = FIX2INT(rb_funcall(tmobj, rb_intern("nsec"), 0)) / 1000000;
|
st.wMilliseconds = FIX2INT(rb_funcall(tmobj, rb_intern("nsec"), 0)) / 1000000;
|
||||||
SystemTimeToVariantTime(&st, &t);
|
SystemTimeToVariantTime(&st, &t);
|
||||||
return t;
|
|
||||||
|
/*
|
||||||
|
* Unfortunately SystemTimeToVariantTime function always ignores the
|
||||||
|
* wMilliseconds of SYSTEMTIME struct.
|
||||||
|
* So, we need to calculate milliseconds by ourselves.
|
||||||
|
*/
|
||||||
|
nsec = FIX2INT(rb_funcall(tmobj, rb_intern("nsec"), 0));
|
||||||
|
nsec /= 1000000.0;
|
||||||
|
nsec /= (24.0 * 3600.0);
|
||||||
|
nsec /= 1000;
|
||||||
|
return t + nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
|
@ -396,6 +396,19 @@ if defined?(WIN32OLE_VARIANT)
|
||||||
assert_equal(789, (t.nsec / 1000000).round)
|
assert_equal(789, (t.nsec / 1000000).round)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_conversion_time2date_with_msec
|
||||||
|
t0 = Time.new(2014, 8, 27, 12, 34, 56)
|
||||||
|
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)
|
||||||
|
|
||||||
|
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))
|
||||||
|
end
|
||||||
|
|
||||||
# this test failed because of VariantTimeToSystemTime
|
# this test failed because of VariantTimeToSystemTime
|
||||||
# and SystemTimeToVariantTime API ignores wMilliseconds
|
# and SystemTimeToVariantTime API ignores wMilliseconds
|
||||||
# member of SYSTEMTIME struct.
|
# member of SYSTEMTIME struct.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue