Signed-off-by: Robert Wilhelm <robert.wilhelm(a)gmx.net>
---
v2: if VT_DATE conversion fails, doing arg -> R8 -> DATE.
---
dlls/vbscript/global.c | 29 +++++++++++++++++++++++++++--
dlls/vbscript/tests/api.vbs | 32 ++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index 5280730f19f..d5d3ec585c0 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -742,8 +742,33 @@ 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)) {
+ hres = VariantChangeType(&v, arg, 0, VT_R8);
+ if(FAILED(hres))
+ return hres;
+ hres = VariantChangeType(&v, &v, 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..a23bb043090 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -1183,6 +1183,38 @@ 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-31#, "CDate(""1"") = " & CDate("1"))
+Call ok(getVT(CDate("1")) = "VT_DATE", "getVT(CDate(""1"")) = " & getVT(CDate("1")))
+If isEnglishLang Then
+ Call ok(CDate("1/1/2000") = #2000-1-1#, "CDate(""1/1/2000"") = " & CDate("1/1/2000"))
+ Call ok(getVT(CDate("1/1/2000")) = "VT_DATE", "getVT(CDate(""1/1/2000"")) = " & getVT(CDate("1/1/2000")))
+End If
+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