jscript: Fix Date_setSeconds implementation.

This commit is contained in:
Piotr Caban 2009-06-22 20:41:11 +02:00 committed by Alexandre Julliard
parent 37883a66fa
commit bbfab68bb8
1 changed files with 58 additions and 3 deletions

View File

@ -958,6 +958,7 @@ static HRESULT Date_setSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPA
VARIANT v; VARIANT v;
HRESULT hres; HRESULT hres;
DateInstance *date; DateInstance *date;
DOUBLE t, sec, ms;
TRACE("\n"); TRACE("\n");
@ -972,12 +973,25 @@ static HRESULT Date_setSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPA
return S_OK; return S_OK;
} }
date = (DateInstance*)dispex;
t = local_time(date->time, date);
hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v); hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
sec = num_val(&v);
date = (DateInstance*)dispex; if(arg_cnt(dp) > 1) {
date->time = time_clip(date->time - (sec_from_time(date->time) - num_val(&v))*1000.0); hres = to_number(dispex->ctx, get_arg(dp, 1), ei, &v);
if(FAILED(hres))
return hres;
ms = num_val(&v);
}
else ms = ms_from_time(t);
t = make_date(day(t), make_time(hour_from_time(t),
min_from_time(t), sec, ms));
date->time = time_clip(utc(t, date));
if(retv) if(retv)
num_set_val(retv, date->time); num_set_val(retv, date->time);
@ -989,7 +1003,48 @@ static HRESULT Date_setSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPA
static HRESULT Date_setUTCSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, static HRESULT Date_setUTCSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{ {
return Date_setSeconds(dispex, lcid, flags, dp, retv, ei, caller); VARIANT v;
HRESULT hres;
DateInstance *date;
DOUBLE t, sec, ms;
TRACE("\n");
if(!is_class(dispex, JSCLASS_DATE)) {
FIXME("throw TypeError\n");
return E_FAIL;
}
if(!arg_cnt(dp)) {
FIXME("throw ArgumentNotOptional\n");
if(retv) num_set_nan(retv);
return S_OK;
}
date = (DateInstance*)dispex;
t = date->time;
hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v);
if(FAILED(hres))
return hres;
sec = num_val(&v);
if(arg_cnt(dp) > 1) {
hres = to_number(dispex->ctx, get_arg(dp, 1), ei, &v);
if(FAILED(hres))
return hres;
ms = num_val(&v);
}
else ms = ms_from_time(t);
t = make_date(day(t), make_time(hour_from_time(t),
min_from_time(t), sec, ms));
date->time = time_clip(t);
if(retv)
num_set_val(retv, date->time);
return S_OK;
} }
/* ECMA-262 3rd Edition 15.9.5.33 */ /* ECMA-262 3rd Edition 15.9.5.33 */