Commit b4d42d2c authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

vbscript: Implement TimeSerial().

parent ea9281d3
...@@ -2144,10 +2144,41 @@ static HRESULT Global_DateSerial(BuiltinDisp *This, VARIANT *args, unsigned args ...@@ -2144,10 +2144,41 @@ static HRESULT Global_DateSerial(BuiltinDisp *This, VARIANT *args, unsigned args
return hres; return hres;
} }
static HRESULT Global_TimeSerial(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) static HRESULT Global_TimeSerial(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
{ {
FIXME("\n"); int hour, minute, second;
return E_NOTIMPL; UDATE ud = {{ 0 }};
HRESULT hres;
double date;
TRACE("\n");
assert(args_cnt == 3);
if (V_VT(args) == VT_NULL || V_VT(args + 1) == VT_NULL || V_VT(args + 2) == VT_NULL)
return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
hres = to_int(args, &hour);
if (SUCCEEDED(hres))
hres = to_int(args + 1, &minute);
if (SUCCEEDED(hres))
hres = to_int(args + 2, &second);
if (SUCCEEDED(hres))
{
ud.st.wYear = 1899;
ud.st.wMonth = 12;
ud.st.wDay = 30;
ud.st.wHour = hour;
ud.st.wMinute = minute;
ud.st.wSecond = second;
hres = VarDateFromUdateEx(&ud, 0, 0, &date);
}
if (SUCCEEDED(hres))
hres = return_date(res, date);
return hres;
} }
static HRESULT Global_InputBox(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) static HRESULT Global_InputBox(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
......
...@@ -2165,4 +2165,41 @@ sub testMonthNameError() ...@@ -2165,4 +2165,41 @@ sub testMonthNameError()
end sub end sub
call testMonthNameError() call testMonthNameError()
sub testTimeSerial(hh, mm, ss, hhexp, mmexp, ssexp, dateexp)
dim x
x = TimeSerial(hh, mm, ss)
call ok(Hour(x) = hhexp, "hour = " & Hour(x) & " expected " & hhexp)
call ok(Minute(x) = mmexp, "minute = " & Minute(x) & " expected " & mmexp)
call ok(Second(x) = ssexp, "second = " & Second(x) & " expected " & ssexp)
call ok(Year(x) = Year(dateexp), "year = " & Year(x))
call ok(Month(x) = Month(dateexp), "month = " & Month(x))
call ok(Day(x) = Day(dateexp), "day = " & Day(x))
call ok(getVT(x) = "VT_DATE*", "getVT = " & getVT(x))
end sub
sub testTimeSerialError()
on error resume next
dim x
call Err.clear()
x = TimeSerial(null, 1, 1)
call ok(Err.number = 94, "Err.number = " & Err.number)
call ok(getVT(x) = "VT_EMPTY*", "getVT = " & getVT(x))
call Err.clear()
call TimeSerial(10, null, 1)
call ok(Err.number = 94, "Err.number = " & Err.number)
call Err.clear()
call TimeSerial(10, 1, null)
call ok(Err.number = 94, "Err.number = " & Err.number)
end sub
call testTimeSerial(0, 0, 0, 0, 0, 0, DateSerial(1899, 12, 30))
call testTimeSerial(10, 2, 1, 10, 2, 1, DateSerial(1899, 12, 30))
call testTimeSerial(0, 2, 1, 0, 2, 1, DateSerial(1899, 12, 30))
call testTimeSerial(24, 2, 1, 0, 2, 1, DateSerial(1899, 12, 31))
call testTimeSerial(25, 2, 1, 1, 2, 1, DateSerial(1899, 12, 31))
call testTimeSerial(50, 2, 1, 2, 2, 1, DateSerial(1900, 1, 1))
call testTimeSerial(10, 60, 2, 11, 0, 2, DateSerial(1899, 12, 30))
call testTimeSerial(10, 0, 60, 10, 1, 0, DateSerial(1899, 12, 30))
call testTimeSerialError()
Call reportSuccess() Call reportSuccess()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment