forked from Mirrors/wine-wine
jscript: Added calling Date as function implementation.
parent
8150960f8c
commit
b5a82030ad
|
@ -455,9 +455,7 @@ static SYSTEMTIME create_systemtime(DOUBLE time)
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ECMA-262 3rd Edition 15.9.1.2 */
|
static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, VARIANT *retv)
|
||||||
static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
|
||||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
|
||||||
{
|
{
|
||||||
static const WCHAR NaNW[] = { 'N','a','N',0 };
|
static const WCHAR NaNW[] = { 'N','a','N',0 };
|
||||||
static const WCHAR formatW[] = { '%','s',' ','%','s',' ','%','d',' ',
|
static const WCHAR formatW[] = { '%','s',' ','%','s',' ','%','d',' ',
|
||||||
|
@ -466,6 +464,9 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
|
||||||
static const WCHAR formatUTCW[] = { '%','s',' ','%','s',' ','%','d',' ',
|
static const WCHAR formatUTCW[] = { '%','s',' ','%','s',' ','%','d',' ',
|
||||||
'%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
|
'%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
|
||||||
'U','T','C',' ','%','d','%','s',0 };
|
'U','T','C',' ','%','d','%','s',0 };
|
||||||
|
static const WCHAR formatNoOffsetW[] = { '%','s',' ','%','s',' ',
|
||||||
|
'%','d',' ','%','0','2','d',':','%','0','2','d',':',
|
||||||
|
'%','0','2','d',' ','%','d','%','s',0 };
|
||||||
static const WCHAR ADW[] = { 0 };
|
static const WCHAR ADW[] = { 0 };
|
||||||
static const WCHAR BCW[] = { ' ','B','.','C','.',0 };
|
static const WCHAR BCW[] = { ' ','B','.','C','.',0 };
|
||||||
|
|
||||||
|
@ -481,23 +482,12 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
|
||||||
|
|
||||||
BOOL formatAD = TRUE;
|
BOOL formatAD = TRUE;
|
||||||
BSTR week, month;
|
BSTR week, month;
|
||||||
DateInstance *date;
|
|
||||||
BSTR date_str;
|
BSTR date_str;
|
||||||
DOUBLE time;
|
int len, size, year, day;
|
||||||
int len, size, year, day, offset;
|
|
||||||
DWORD lcid_en, week_id, month_id;
|
DWORD lcid_en, week_id, month_id;
|
||||||
WCHAR sign = '-';
|
WCHAR sign = '-';
|
||||||
|
|
||||||
TRACE("\n");
|
if(isnan(time)) {
|
||||||
|
|
||||||
if(!is_class(dispex, JSCLASS_DATE)) {
|
|
||||||
FIXME("throw TypeError\n");
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
date = (DateInstance*)dispex;
|
|
||||||
|
|
||||||
if(isnan(date->time)) {
|
|
||||||
if(retv) {
|
if(retv) {
|
||||||
V_VT(retv) = VT_BSTR;
|
V_VT(retv) = VT_BSTR;
|
||||||
V_BSTR(retv) = SysAllocString(NaNW);
|
V_BSTR(retv) = SysAllocString(NaNW);
|
||||||
|
@ -507,8 +497,6 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
time = local_time(date->time, date);
|
|
||||||
|
|
||||||
if(retv) {
|
if(retv) {
|
||||||
len = 21;
|
len = 21;
|
||||||
|
|
||||||
|
@ -554,10 +542,8 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
|
||||||
} while(day);
|
} while(day);
|
||||||
day = date_from_time(time);
|
day = date_from_time(time);
|
||||||
|
|
||||||
offset = date->bias +
|
if(!show_offset) len -= 9;
|
||||||
daylight_saving_ta(time, date);
|
else if(offset == 0) len -= 5;
|
||||||
|
|
||||||
if(offset == 0) len -= 5;
|
|
||||||
else if(offset < 0) {
|
else if(offset < 0) {
|
||||||
sign = '+';
|
sign = '+';
|
||||||
offset = -offset;
|
offset = -offset;
|
||||||
|
@ -570,15 +556,19 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(offset)
|
if(!show_offset)
|
||||||
|
sprintfW(date_str, formatNoOffsetW, week, month, day,
|
||||||
|
(int)hour_from_time(time), (int)min_from_time(time),
|
||||||
|
(int)sec_from_time(time), year, formatAD?ADW:BCW);
|
||||||
|
else if(offset)
|
||||||
sprintfW(date_str, formatW, week, month, day,
|
sprintfW(date_str, formatW, week, month, day,
|
||||||
(int)hour_from_time(time), (int)min_from_time(time),
|
(int)hour_from_time(time), (int)min_from_time(time),
|
||||||
(int)sec_from_time(time), sign, offset/60, offset%60,
|
(int)sec_from_time(time), sign, offset/60, offset%60,
|
||||||
year, formatAD?ADW:BCW);
|
year, formatAD?ADW:BCW);
|
||||||
else
|
else
|
||||||
sprintfW(date_str, formatUTCW, week, month, day,
|
sprintfW(date_str, formatUTCW, week, month, day,
|
||||||
(int)hour_from_time(time), (int)min_from_time(time),
|
(int)hour_from_time(time), (int)min_from_time(time),
|
||||||
(int)sec_from_time(time), year, formatAD?ADW:BCW);
|
(int)sec_from_time(time), year, formatAD?ADW:BCW);
|
||||||
|
|
||||||
SysFreeString(week);
|
SysFreeString(week);
|
||||||
SysFreeString(month);
|
SysFreeString(month);
|
||||||
|
@ -589,6 +579,29 @@ static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARA
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ECMA-262 3rd Edition 15.9.1.2 */
|
||||||
|
static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||||
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
||||||
|
{
|
||||||
|
DateInstance *date;
|
||||||
|
DOUBLE time;
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
TRACE("\n");
|
||||||
|
|
||||||
|
if(!is_class(dispex, JSCLASS_DATE)) {
|
||||||
|
FIXME("throw TypeError\n");
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
date = (DateInstance*)dispex;
|
||||||
|
time = local_time(date->time, date);
|
||||||
|
offset = date->bias +
|
||||||
|
daylight_saving_ta(time, date);
|
||||||
|
|
||||||
|
return date_to_string(time, TRUE, offset, retv);
|
||||||
|
}
|
||||||
|
|
||||||
/* ECMA-262 3rd Edition 15.9.1.5 */
|
/* ECMA-262 3rd Edition 15.9.1.5 */
|
||||||
static HRESULT Date_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
static HRESULT Date_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
|
||||||
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
|
||||||
|
@ -2652,6 +2665,18 @@ static HRESULT DateConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPP
|
||||||
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(date);
|
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(date);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
||||||
|
case INVOKE_FUNC: {
|
||||||
|
FILETIME system_time, local_time;
|
||||||
|
LONGLONG lltime;
|
||||||
|
|
||||||
|
GetSystemTimeAsFileTime(&system_time);
|
||||||
|
FileTimeToLocalFileTime(&system_time, &local_time);
|
||||||
|
lltime = ((LONGLONG)local_time.dwHighDateTime<<32)
|
||||||
|
+ local_time.dwLowDateTime;
|
||||||
|
|
||||||
|
return date_to_string(lltime/10000-TIME_EPOCH, FALSE, 0, retv);
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
FIXME("unimplemented flags %x\n", flags);
|
FIXME("unimplemented flags %x\n", flags);
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
|
|
Loading…
Reference in New Issue