vbscript: Implement Weekday().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
0f44081775
commit
da966b4d46
|
@ -1982,10 +1982,50 @@ static HRESULT Global_Month(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt,
|
|||
return FAILED(hres) ? hres : return_short(res, st.wMonth);
|
||||
}
|
||||
|
||||
static HRESULT Global_Weekday(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
|
||||
static HRESULT Global_Weekday(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
|
||||
{
|
||||
FIXME("\n");
|
||||
return E_NOTIMPL;
|
||||
HRESULT hres = S_OK;
|
||||
int first_day = 0;
|
||||
SYSTEMTIME st;
|
||||
|
||||
TRACE("(%s)\n", debugstr_variant(args));
|
||||
|
||||
assert(args_cnt == 1 || args_cnt == 2);
|
||||
|
||||
/* [vbSunday = 1, vbSaturday = 7] -> wDayOfWeek [0, 6] */
|
||||
if (args_cnt == 2)
|
||||
{
|
||||
if (V_VT(args + 1) == VT_NULL)
|
||||
return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
|
||||
|
||||
hres = to_int(args + 1, &first_day);
|
||||
if (SUCCEEDED(hres))
|
||||
{
|
||||
if (!first_day)
|
||||
{
|
||||
/* vbUseSystemDayOfWeek */
|
||||
GetLocaleInfoW(This->ctx->lcid, LOCALE_RETURN_NUMBER | LOCALE_IFIRSTDAYOFWEEK, (LPWSTR)&first_day,
|
||||
sizeof(&first_day) / sizeof(WCHAR));
|
||||
first_day = (first_day + 1) % 7;
|
||||
}
|
||||
else if (first_day >= 1 && first_day <= 7)
|
||||
{
|
||||
first_day--;
|
||||
}
|
||||
else
|
||||
return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILED(hres))
|
||||
return hres;
|
||||
|
||||
if (V_VT(args) == VT_NULL)
|
||||
return return_null(res);
|
||||
|
||||
if (FAILED(hres = to_system_time(args, &st))) return hres;
|
||||
|
||||
return return_short(res, 1 + (7 - first_day + st.wDayOfWeek) % 7);
|
||||
}
|
||||
|
||||
static HRESULT Global_Year(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
|
||||
|
|
|
@ -2036,4 +2036,57 @@ call testDateAdd(DateSerial(2000, 1, 1), "ww", -1, DateSerial(1999, 12, 25))
|
|||
call testDateAdd(DateSerial(2000, 1, 1), "Ww", -1, DateSerial(1999, 12, 25))
|
||||
call testDateAddError()
|
||||
|
||||
sub testWeekday(d, firstday, wd)
|
||||
dim x, x2
|
||||
x = Weekday(d, firstday)
|
||||
call ok(x = wd, "weekday = " & x & " expected " & wd)
|
||||
call ok(getVT(x) = "VT_I2*", "getVT = " & getVT(x))
|
||||
if firstday = vbSunday then
|
||||
x = Weekday(d)
|
||||
call ok(x = wd, "weekday = " & x & " expected " & wd)
|
||||
end if
|
||||
x = Weekday(d, vbUseSystemDayOfWeek)
|
||||
x2 = Weekday(d, firstDayOfWeek)
|
||||
call ok(x = x2, "weekday = " & x & " expected " & x2)
|
||||
end sub
|
||||
|
||||
sub testWeekdayError()
|
||||
on error resume next
|
||||
dim x
|
||||
call Err.clear()
|
||||
call Weekday(DateSerial(1000, 1, 1), 10)
|
||||
call ok(Err.number = 5, "Err.number = " & Err.number)
|
||||
call Err.clear()
|
||||
call Weekday(DateSerial(1000, 1, 1), -1)
|
||||
call ok(Err.number = 5, "Err.number = " & Err.number)
|
||||
call Err.clear()
|
||||
call Weekday(null, -1)
|
||||
call ok(Err.number = 5, "Err.number = " & Err.number)
|
||||
call Err.clear()
|
||||
call Weekday(DateSerial(1000, 1, 1), null)
|
||||
call ok(Err.number = 94, "Err.number = " & Err.number)
|
||||
call Err.clear()
|
||||
x = Weekday(null, vbSunday)
|
||||
call ok(Err.number = 0, "Err.number = " & Err.number)
|
||||
call ok(getVT(x) = "VT_NULL*", "getVT = " & getVT(x))
|
||||
call Err.clear()
|
||||
call Weekday(null, null)
|
||||
call ok(Err.number = 94, "Err.number = " & Err.number)
|
||||
call Err.clear()
|
||||
call Weekday(null, "a")
|
||||
call ok(Err.number = 13, "Err.number = " & Err.number)
|
||||
call Err.clear()
|
||||
call Weekday(DateSerial(1000, 1, 1), "a")
|
||||
call ok(Err.number = 13, "Err.number = " & Err.number)
|
||||
end sub
|
||||
|
||||
call testWeekday(DateSerial(2000, 1, 1), vbSunday, 7)
|
||||
call testWeekday(DateSerial(2000, 1, 1), vbMonday, 6)
|
||||
call testWeekday(DateSerial(2000, 1, 1), vbTuesday, 5)
|
||||
call testWeekday(DateSerial(2000, 1, 1), vbWednesday, 4)
|
||||
call testWeekday(DateSerial(2000, 1, 1), vbThursday, 3)
|
||||
call testWeekday(DateSerial(2000, 1, 1), vbFriday, 2)
|
||||
call testWeekday(DateSerial(2000, 1, 1), vbSaturday, 1)
|
||||
call testWeekdayError()
|
||||
|
||||
Call reportSuccess()
|
||||
|
|
Loading…
Reference in New Issue