[PATCH 1/2] vbscript: Implement DateSerial().

Nikolay Sivov nsivov at codeweavers.com
Sun May 15 07:50:56 CDT 2022


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/vbscript/global.c      | 35 ++++++++++++++++++++++++++++++++---
 dlls/vbscript/tests/api.vbs | 28 ++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index ab06db87624..da3da1f04d8 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -2044,10 +2044,39 @@ static HRESULT Global_TimeValue(BuiltinDisp *This, VARIANT *arg, unsigned args_c
     return E_NOTIMPL;
 }
 
-static HRESULT Global_DateSerial(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
+static HRESULT Global_DateSerial(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    int year, month, day;
+    SYSTEMTIME lt;
+    HRESULT hres;
+    double date;
+    UDATE ud;
+
+    TRACE("\n");
+
+    assert(args_cnt == 3);
+
+    hres = to_int(args, &year);
+    if (SUCCEEDED(hres))
+        hres = to_int(args + 1, &month);
+    if (SUCCEEDED(hres))
+        hres = to_int(args + 2, &day);
+
+    if (SUCCEEDED(hres))
+    {
+        lt.wYear = year;
+        lt.wMonth = month;
+        lt.wDay = day;
+
+        ud.st = lt;
+        ud.wDayOfYear = 0;
+        hres = VarDateFromUdateEx(&ud, 0, 0, &date);
+    }
+
+    if (SUCCEEDED(hres))
+        hres = return_date(res, date);
+
+    return hres;
 }
 
 static HRESULT Global_TimeSerial(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs
index 20798a0aacd..f65789184e0 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -1958,4 +1958,32 @@ sub testErrRaise()
 end sub
 call testErrRaise()
 
+sub testDateSerial(yy, mm, dd, yyexp, mmexp, ddexp)
+    dim x
+    x = DateSerial(yy, mm, dd)
+    call ok(Year(x) = yyexp, "year = " & Year(x) & " expected " & yyexp)
+    call ok(Month(x) = mmexp, "month = " & Month(x) & " expected " & mmexp)
+    call ok(Day(x) = ddexp, "day = " & Day(x) & " expected " & ddexp)
+    call ok(getVT(x) = "VT_DATE*", "getVT = " & getVT(x))
+end sub
+
+sub testDateSerialError()
+    on error resume next
+    call Err.clear()
+    call DateSerial(10000, 1, 1)
+    call ok(Err.number = 5, "Err.number = " & Err.number)
+    call Err.clear()
+    call DateSerial(-10000, 1, 1)
+    call ok(Err.number = 5, "Err.number = " & Err.number)
+end sub
+
+call testDateSerial(100, 2, 1, 100, 2, 1)
+call testDateSerial(0, 2, 1, 2000, 2, 1)
+call testDateSerial(49, 2, 1, 2049, 2, 1)
+call testDateSerial(50, 2, 1, 1950, 2, 1)
+call testDateSerial(99, 2, 1, 1999, 2, 1)
+call testDateSerial(2000, 14, 2, 2001, 2, 2)
+call testDateSerial(9999, 12, 1, 9999, 12, 1)
+call testDateSerialError()
+
 Call reportSuccess()
-- 
2.35.1




More information about the wine-devel mailing list