Module: wine Branch: master Commit: b0915dfb5737fc2665fe897e27ed538689ad973c URL: https://gitlab.winehq.org/wine/wine/-/commit/b0915dfb5737fc2665fe897e27ed538...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Wed Nov 16 17:06:33 2022 +0300
vbscript: Implement FormatDateTime().
---
dlls/vbscript/global.c | 28 +++++++++++++++++++++++++--- dlls/vbscript/tests/api.vbs | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 73049a5e77f..f6995cb55d7 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -3015,10 +3015,32 @@ static HRESULT Global_FormatPercent(BuiltinDisp *This, VARIANT *args, unsigned a return return_bstr(res, str); }
-static HRESULT Global_FormatDateTime(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) +static HRESULT Global_FormatDateTime(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + int format = 0; + HRESULT hres; + BSTR str; + + TRACE("\n"); + + assert(1 <= args_cnt && args_cnt <= 2); + + if (V_VT(args) == VT_NULL) + return MAKE_VBSERROR(VBSE_TYPE_MISMATCH); + + if (args_cnt == 2) + { + if (V_VT(args+1) == VT_NULL) return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE); + if (V_VT(args+1) != VT_ERROR) + { + if (FAILED(hres = to_int(args+1, &format))) return hres; + } + } + + hres = VarFormatDateTime(args, format, 0, &str); + if (FAILED(hres)) return hres; + + return return_bstr(res, str); }
static HRESULT Global_WeekdayName(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index ecae726d229..01e034bd73e 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -2411,4 +2411,29 @@ end sub call testFormatPercent() call testFormatPercentError()
+sub testFormatDateTimeError() + on error resume next + dim x + call Err.clear() + x = FormatDateTime(null) + call ok(Err.number = 13, "Err.number = " & Err.number) + call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x)) + call Err.clear() + x = FormatDateTime(.10,null) + call ok(Err.number = 94, "Err.number = " & Err.number) + call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x)) +end sub + +sub testFormatDateTime() + dim x + + x = FormatDateTime(0) + call ok(getVT(x) = "VT_BSTR*", "getVT = " & getVT(x)) + x = FormatDateTime(0.1,1) + call ok(getVT(x) = "VT_BSTR*", "getVT = " & getVT(x)) +end sub + +call testFormatDateTime() +call testFormatDateTimeError() + Call reportSuccess()