Signed-off-by: Robert Wilhelm robert.wilhelm@gmx.net --- dlls/vbscript/global.c | 23 +++++++++++++++++++++-- dlls/vbscript/tests/api.vbs | 26 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 5280730f19f..a6bab83f3e6 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -742,8 +742,27 @@ static HRESULT Global_CByte(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt,
static HRESULT Global_CDate(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + VARIANT v; + HRESULT hres; + + TRACE("%s\n", debugstr_variant(arg)); + + assert(args_cnt == 1); + + if(V_VT(arg) == VT_NULL) + return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE); + + V_VT(&v) = VT_EMPTY; + hres = VariantChangeType(&v, arg, 0, VT_DATE); + if(FAILED(hres)) + return hres; + + if(!res) + return DISP_E_BADVARTYPE; + else { + *res = v; + return S_OK; + } }
static HRESULT Global_CDbl(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 0e5b0ee6d37..b84a1fa060b 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -1183,6 +1183,32 @@ MyObject.myval = 0 Call ok(CCur(MyObject) = 0, "CCur(MyObject) = " & CCur(MyObject)) Call ok(getVT(CCur(MyObject)) = "VT_CY", "getVT(CCur(MyObject)) = " & getVT(CCur(MyObject)))
+Sub testCDateError(strings, error_num1, error_num2) + on error resume next + Dim x + + Call Err.clear() + x = CDate(strings) + Call ok(Err.number = error_num1, "Err.number = " & Err.number) + + Call Err.clear() + Call CDate(strings) + Call ok(Err.number = error_num2, "Err.number = " & Err.number) +End Sub + +Call ok(CDate(Empty) = 0, "CDate(Empty) = " & CDate(Empty)) +Call ok(getVT(CDate(Empty)) = "VT_DATE", "getVT(CDate(Empty)) = " & getVT(CDate(Empty))) +Call ok(CDate(0) = 0, "CDate(0) = " & CDate(0)) +Call ok(getVT(CDate(0)) = "VT_DATE", "getVT(CDate(0)) = " & getVT(CDate(0))) +Call ok(CDate(1) = #1899-12-31#, "CDate(1) = " & CDate(1)) +Call ok(getVT(CDate(1)) = "VT_DATE", "getVT(CDate(1)) = " & getVT(CDate(1))) +Call ok(CDate(-1) = #1899-12-29#, "CDate(-1) = " & CDate(-1)) +Call ok(getVT(CDate(-1)) = "VT_DATE", "getVT(CDate(-1)) = " & getVT(CDate(-1))) +Call ok(CDate(100000) = #2173-10-14#, "CDate(100000) = " & CDate(100000)) +Call ok(getVT(CDate(100000)) = "VT_DATE", "getVT(CDate(100000)) = " & getVT(CDate(100000))) +Call testCDateError("", 13, 13) +Call testCDateError(null, 94, 94) + Sub testCDblError(strings, error_num1, error_num2) on error resume next Dim x -- 2.36.1
This doesn't work for string arguments, e.g. CDate("1").
This doesn't work for string arguments, e.g. CDate("1").
Thanks. Seems CDate("1/2/2000") works, but for CDate("1") I get type mismatch from VariantChangeType. I will try to improve my patch.
On 5/20/22 14:25, Robert Wilhelm wrote:
This doesn't work for string arguments, e.g. CDate("1").
Thanks. Seems CDate("1/2/2000") works, but for CDate("1") I get type mismatch from VariantChangeType. I will try to improve my patch.
Maybe this could be an alternate path if VT_DATE conversion fails, doing arg -> R8 -> DATE.