From 3fb0e893b1ae72a2748e2b51ae75d6a053a52ccc Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 19 Jan 2021 14:33:39 +0100 Subject: [PATCH] jscript: Support VT_DATE to number conversion. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/date.c | 21 +++++++++++++++++++++ dlls/jscript/jscript.h | 1 + dlls/jscript/jsutils.c | 13 ++++++++++--- dlls/jscript/tests/lang.js | 11 +++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c index ffd8e212693..c0264c26bb8 100644 --- a/dlls/jscript/date.c +++ b/dlls/jscript/date.c @@ -2462,3 +2462,24 @@ HRESULT create_date_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp jsdisp_release(&date->dispex); return hres; } + +HRESULT variant_date_to_number(double date, double *ret) +{ + SYSTEMTIME st; + UDATE udate; + HRESULT hres; + + hres = VarUdateFromDate(date, 0, &udate); + if(FAILED(hres)) + return hres; + + if(!TzSpecificLocalTimeToSystemTime(NULL, &udate.st, &st)) + return E_FAIL; + + TRACE("%uy %um %u %ud %uh %um %u.%us\n", st.wYear, st.wMonth, st.wDayOfWeek, st.wDay, st.wHour, st.wMinute, + st.wSecond, st.wMilliseconds); + + *ret = make_date(make_day(st.wYear, st.wMonth - 1, st.wDay), + make_time(st.wHour, st.wMinute, st.wSecond, st.wMilliseconds)); + return S_OK; +} diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index dfe087521db..7cc194b84b9 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -360,6 +360,7 @@ HRESULT to_object(script_ctx_t*,jsval_t,IDispatch**) DECLSPEC_HIDDEN; HRESULT jsval_strict_equal(jsval_t,jsval_t,BOOL*) DECLSPEC_HIDDEN; HRESULT variant_change_type(script_ctx_t*,VARIANT*,VARIANT*,VARTYPE) DECLSPEC_HIDDEN; +HRESULT variant_date_to_number(double,double*) DECLSPEC_HIDDEN; HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN; diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index a2ac53f64b9..a77c70ad01d 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -611,9 +611,16 @@ HRESULT to_number(script_ctx_t *ctx, jsval_t val, double *ret) case JSV_BOOL: *ret = get_bool(val) ? 1 : 0; return S_OK; - case JSV_VARIANT: - FIXME("unimplemented for variant %s\n", debugstr_variant(get_variant(val))); - return E_NOTIMPL; + case JSV_VARIANT: { + const VARIANT *v = get_variant(val); + switch(V_VT(v)) { + case VT_DATE: + return variant_date_to_number(V_DATE(v), ret); + default: + FIXME("unimplemented for variant %s\n", debugstr_variant(v)); + return E_NOTIMPL; + } + } }; assert(0); diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index dfe33f2f615..d6973099b7c 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -197,6 +197,17 @@ ok(tmp === 3, "tmp = " + tmp); d = v_date(0); e = Date.parse("Sat Dec 30 00:00:00 1899"); ok(getVT(d) === "VT_DATE", "vt v_date(0) = " + getVT(d)); + ok(getVT(+d) === "VT_R8", "vt +v_date(0) = " + getVT(d)); + ok(getVT(d / d) === "VT_I4", "vt v_date(0) / v_date(0) = " + getVT(d / d)); + ok((+d) === e, "+v_date(0) = " + (+d) + " expected " + e); + + d = v_date(2.5); + e = Date.parse("Mon Jan 1 12:00:00 1900"); + ok((+d) === e, "+v_date(2.5) = " + (+d)); + + d = v_date(42091); + e = Date.parse("Sat Mar 28 00:00:00 2015"); + ok((+d) === e, "+v_date(2015y) = " + (+d) + " expected " + e); })(); function testRecFunc(x) {