gdi32: Make test_font_metrics require the font being selected into the DC.
[wine/multimedia.git] / dlls / jscript / date.c
blob3fee568e106414813f35d8038c6bb271317e61ae
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "jscript.h"
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
25 typedef struct {
26 DispatchEx dispex;
27 } DateInstance;
29 static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
30 static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
31 static const WCHAR hasOwnPropertyW[] = {'h','a','s','O','w','n','P','r','o','p','e','r','t','y',0};
32 static const WCHAR propertyIsEnumerableW[] =
33 {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
34 static const WCHAR isPrototypeOfW[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
35 static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
36 static const WCHAR toUTCStringW[] = {'t','o','U','T','C','S','t','r','i','n','g',0};
37 static const WCHAR toDateStringW[] = {'t','o','D','a','t','e','S','t','r','i','n','g',0};
38 static const WCHAR toTimeStringW[] = {'t','o','T','i','m','e','S','t','r','i','n','g',0};
39 static const WCHAR toLocaleDateStringW[] = {'t','o','L','o','c','a','l','e','D','a','t','e','S','t','r','i','n','g',0};
40 static const WCHAR toLocaleTimeStringW[] = {'t','o','L','o','c','a','l','e','T','i','m','e','S','t','r','i','n','g',0};
41 static const WCHAR getTimeW[] = {'g','e','t','T','i','m','e',0};
42 static const WCHAR getFullYearW[] = {'g','e','t','F','u','l','l','Y','e','a','r',0};
43 static const WCHAR getUTCFullYearW[] = {'g','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
44 static const WCHAR getMonthW[] = {'g','e','t','M','o','n','t','h',0};
45 static const WCHAR getUTCMonthW[] = {'g','e','t','U','T','C','M','o','n','t','h',0};
46 static const WCHAR getDateW[] = {'g','e','t','D','a','t','e',0};
47 static const WCHAR getUTCDateW[] = {'g','e','t','U','T','C','D','a','t','e',0};
48 static const WCHAR getDayW[] = {'g','e','t','D','a','y',0};
49 static const WCHAR getUTCDayW[] = {'g','e','t','U','T','C','D','a','y',0};
50 static const WCHAR getHoursW[] = {'g','e','t','H','o','u','r','s',0};
51 static const WCHAR getUTCHoursW[] = {'g','e','t','U','T','C','H','o','u','r','s',0};
52 static const WCHAR getMinutesW[] = {'g','e','t','M','i','n','u','t','e','s',0};
53 static const WCHAR getUTCMinutesW[] = {'g','e','t','U','T','C','M','i','n','u','t','e','s',0};
54 static const WCHAR getSecondsW[] = {'g','e','t','S','e','c','o','n','d','s',0};
55 static const WCHAR getUTCSecondsW[] = {'g','e','t','U','T','C','S','e','c','o','n','d','s',0};
56 static const WCHAR getMilisecondsW[] = {'g','e','t','M','i','l','i','s','e','c','o','n','d','s',0};
57 static const WCHAR getUTCMilisecondsW[] = {'g','e','t','U','T','C','M','i','l','i','s','e','c','o','n','d','s',0};
58 static const WCHAR getTimezoneOffsetW[] = {'g','e','t','T','i','m','e','z','o','n','e','O','f','f','s','e','t',0};
59 static const WCHAR setTimeW[] = {'s','e','t','T','i','m','e',0};
60 static const WCHAR setMilisecondsW[] = {'s','e','t','M','i','l','i','s','e','c','o','n','d','s',0};
61 static const WCHAR setUTCMilisecondsW[] = {'s','e','t','U','T','C','M','i','l','i','s','e','c','o','n','d','s',0};
62 static const WCHAR setSecondsW[] = {'s','e','t','S','e','c','o','n','d','s',0};
63 static const WCHAR setUTCSecondsW[] = {'s','e','t','U','T','C','S','e','c','o','n','d','s',0};
64 static const WCHAR setMinutesW[] = {'s','e','t','M','i','n','u','t','e','s',0};
65 static const WCHAR setUTCMinutesW[] = {'s','e','t','U','T','C','M','i','n','u','t','e','s',0};
66 static const WCHAR setHoursW[] = {'s','e','t','H','o','u','r','s',0};
67 static const WCHAR setUTCHoursW[] = {'s','e','t','H','o','u','r','s',0};
68 static const WCHAR setDateW[] = {'s','e','t','D','a','t','e',0};
69 static const WCHAR setUTCDateW[] = {'s','e','t','U','T','C','D','a','t','e',0};
70 static const WCHAR setMonthW[] = {'s','e','t','M','o','n','t','h',0};
71 static const WCHAR setUTCMonthW[] = {'s','e','t','U','T','C','M','o','n','t','h',0};
72 static const WCHAR setFullYearW[] = {'s','e','t','F','u','l','l','Y','e','a','r',0};
73 static const WCHAR setUTCFullYearW[] = {'s','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
75 static inline HRESULT systime_to_time(const SYSTEMTIME *st, FILETIME *time)
77 return SystemTimeToFileTime(st, time) ? S_OK : HRESULT_FROM_WIN32(GetLastError());
80 static HRESULT Date_toString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
81 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
83 FIXME("\n");
84 return E_NOTIMPL;
87 static HRESULT Date_toLocaleString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
88 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
90 FIXME("\n");
91 return E_NOTIMPL;
94 static HRESULT Date_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
95 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
97 FIXME("\n");
98 return E_NOTIMPL;
101 static HRESULT Date_propertyIsEnumerable(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
102 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
104 FIXME("\n");
105 return E_NOTIMPL;
108 static HRESULT Date_isPrototypeOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
109 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
111 FIXME("\n");
112 return E_NOTIMPL;
115 static HRESULT Date_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
116 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
118 FIXME("\n");
119 return E_NOTIMPL;
122 static HRESULT Date_toUTCString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
123 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
125 FIXME("\n");
126 return E_NOTIMPL;
129 static HRESULT Date_toDateString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
130 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
132 FIXME("\n");
133 return E_NOTIMPL;
136 static HRESULT Date_toTimeString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
137 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
139 FIXME("\n");
140 return E_NOTIMPL;
143 static HRESULT Date_toLocaleDateString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
144 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
146 FIXME("\n");
147 return E_NOTIMPL;
150 static HRESULT Date_toLocaleTimeString(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
151 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
153 FIXME("\n");
154 return E_NOTIMPL;
157 static HRESULT Date_getTime(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
158 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
160 FIXME("\n");
161 return E_NOTIMPL;
164 static HRESULT Date_getFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
165 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
167 FIXME("\n");
168 return E_NOTIMPL;
171 static HRESULT Date_getUTCFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
172 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
174 FIXME("\n");
175 return E_NOTIMPL;
178 static HRESULT Date_getMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
179 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
181 FIXME("\n");
182 return E_NOTIMPL;
185 static HRESULT Date_getUTCMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
186 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
188 FIXME("\n");
189 return E_NOTIMPL;
192 static HRESULT Date_getDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
193 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
195 FIXME("\n");
196 return E_NOTIMPL;
199 static HRESULT Date_getUTCDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
200 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
202 FIXME("\n");
203 return E_NOTIMPL;
206 static HRESULT Date_getDay(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
207 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
209 FIXME("\n");
210 return E_NOTIMPL;
213 static HRESULT Date_getUTCDay(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
214 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
216 FIXME("\n");
217 return E_NOTIMPL;
220 static HRESULT Date_getHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
221 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
223 FIXME("\n");
224 return E_NOTIMPL;
227 static HRESULT Date_getUTCHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
228 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
230 FIXME("\n");
231 return E_NOTIMPL;
234 static HRESULT Date_getMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
235 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
237 FIXME("\n");
238 return E_NOTIMPL;
241 static HRESULT Date_getUTCMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
242 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
244 FIXME("\n");
245 return E_NOTIMPL;
248 static HRESULT Date_getSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
249 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
251 FIXME("\n");
252 return E_NOTIMPL;
255 static HRESULT Date_getUTCSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
256 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
258 FIXME("\n");
259 return E_NOTIMPL;
262 static HRESULT Date_getMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
263 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
265 FIXME("\n");
266 return E_NOTIMPL;
269 static HRESULT Date_getUTCMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
270 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
272 FIXME("\n");
273 return E_NOTIMPL;
276 static HRESULT Date_getTimezoneOffset(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
277 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
279 FIXME("\n");
280 return E_NOTIMPL;
283 static HRESULT Date_setTime(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
284 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
286 FIXME("\n");
287 return E_NOTIMPL;
290 static HRESULT Date_setMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
291 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
293 FIXME("\n");
294 return E_NOTIMPL;
297 static HRESULT Date_setUTCMiliseconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
298 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
300 FIXME("\n");
301 return E_NOTIMPL;
304 static HRESULT Date_setSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
305 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
307 FIXME("\n");
308 return E_NOTIMPL;
311 static HRESULT Date_setUTCSeconds(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
312 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
314 FIXME("\n");
315 return E_NOTIMPL;
318 static HRESULT Date_setMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
319 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
321 FIXME("\n");
322 return E_NOTIMPL;
325 static HRESULT Date_setUTCMinutes(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
326 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
328 FIXME("\n");
329 return E_NOTIMPL;
332 static HRESULT Date_setHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
333 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
335 FIXME("\n");
336 return E_NOTIMPL;
339 static HRESULT Date_setUTCHours(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
340 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
342 FIXME("\n");
343 return E_NOTIMPL;
346 static HRESULT Date_setDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
347 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
349 FIXME("\n");
350 return E_NOTIMPL;
353 static HRESULT Date_setUTCDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
354 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
356 FIXME("\n");
357 return E_NOTIMPL;
360 static HRESULT Date_setMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
361 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
363 FIXME("\n");
364 return E_NOTIMPL;
367 static HRESULT Date_setUTCMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
368 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
370 FIXME("\n");
371 return E_NOTIMPL;
374 static HRESULT Date_setFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
375 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
377 FIXME("\n");
378 return E_NOTIMPL;
381 static HRESULT Date_setUTCFullYear(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
382 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
384 FIXME("\n");
385 return E_NOTIMPL;
388 static HRESULT Date_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
389 VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
391 FIXME("\n");
392 return E_NOTIMPL;
395 static const builtin_prop_t Date_props[] = {
396 {getDateW, Date_getDate, PROPF_METHOD},
397 {getDayW, Date_getDay, PROPF_METHOD},
398 {getFullYearW, Date_getFullYear, PROPF_METHOD},
399 {getHoursW, Date_getHours, PROPF_METHOD},
400 {getMilisecondsW, Date_getMiliseconds, PROPF_METHOD},
401 {getMinutesW, Date_getMinutes, PROPF_METHOD},
402 {getMonthW, Date_getMonth, PROPF_METHOD},
403 {getSecondsW, Date_getSeconds, PROPF_METHOD},
404 {getTimeW, Date_getTime, PROPF_METHOD},
405 {getTimezoneOffsetW, Date_getTimezoneOffset, PROPF_METHOD},
406 {getUTCDateW, Date_getUTCDate, PROPF_METHOD},
407 {getUTCDayW, Date_getUTCDay, PROPF_METHOD},
408 {getUTCFullYearW, Date_getUTCFullYear, PROPF_METHOD},
409 {getUTCHoursW, Date_getUTCHours, PROPF_METHOD},
410 {getUTCMilisecondsW, Date_getUTCMiliseconds, PROPF_METHOD},
411 {getUTCMinutesW, Date_getUTCMinutes, PROPF_METHOD},
412 {getUTCMonthW, Date_getUTCMonth, PROPF_METHOD},
413 {getUTCSecondsW, Date_getUTCSeconds, PROPF_METHOD},
414 {hasOwnPropertyW, Date_hasOwnProperty, PROPF_METHOD},
415 {isPrototypeOfW, Date_isPrototypeOf, PROPF_METHOD},
416 {propertyIsEnumerableW, Date_propertyIsEnumerable, PROPF_METHOD},
417 {setDateW, Date_setDate, PROPF_METHOD},
418 {setFullYearW, Date_setFullYear, PROPF_METHOD},
419 {setHoursW, Date_setHours, PROPF_METHOD},
420 {setMilisecondsW, Date_setMiliseconds, PROPF_METHOD},
421 {setMinutesW, Date_setMinutes, PROPF_METHOD},
422 {setMonthW, Date_setMonth, PROPF_METHOD},
423 {setSecondsW, Date_setSeconds, PROPF_METHOD},
424 {setTimeW, Date_setTime, PROPF_METHOD},
425 {setUTCDateW, Date_setUTCDate, PROPF_METHOD},
426 {setUTCFullYearW, Date_setUTCFullYear, PROPF_METHOD},
427 {setUTCHoursW, Date_setUTCHours, PROPF_METHOD},
428 {setUTCMilisecondsW, Date_setUTCMiliseconds, PROPF_METHOD},
429 {setUTCMinutesW, Date_setUTCMinutes, PROPF_METHOD},
430 {setUTCMonthW, Date_setUTCMonth, PROPF_METHOD},
431 {setUTCSecondsW, Date_setUTCSeconds, PROPF_METHOD},
432 {toDateStringW, Date_toDateString, PROPF_METHOD},
433 {toLocaleDateStringW, Date_toLocaleDateString, PROPF_METHOD},
434 {toLocaleStringW, Date_toLocaleString, PROPF_METHOD},
435 {toLocaleTimeStringW, Date_toLocaleTimeString, PROPF_METHOD},
436 {toStringW, Date_toString, PROPF_METHOD},
437 {toTimeStringW, Date_toTimeString, PROPF_METHOD},
438 {toUTCStringW, Date_toUTCString, PROPF_METHOD},
439 {valueOfW, Date_valueOf, PROPF_METHOD},
442 static const builtin_info_t Date_info = {
443 JSCLASS_DATE,
444 {NULL, Date_value, 0},
445 sizeof(Date_props)/sizeof(*Date_props),
446 Date_props,
447 NULL,
448 NULL
451 static HRESULT create_date(script_ctx_t *ctx, BOOL use_constr, DispatchEx **ret)
453 DateInstance *date;
454 HRESULT hres;
456 date = heap_alloc_zero(sizeof(DateInstance));
457 if(!date)
458 return E_OUTOFMEMORY;
460 if(use_constr)
461 hres = init_dispex_from_constr(&date->dispex, ctx, &Date_info, ctx->date_constr);
462 else
463 hres = init_dispex(&date->dispex, ctx, &Date_info, NULL);
464 if(FAILED(hres)) {
465 heap_free(date);
466 return hres;
469 *ret = &date->dispex;
470 return S_OK;
473 static HRESULT DateConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
474 VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
476 FIXME("\n");
477 return E_NOTIMPL;
480 HRESULT create_date_constr(script_ctx_t *ctx, DispatchEx **ret)
482 DispatchEx *date;
483 HRESULT hres;
485 hres = create_date(ctx, FALSE, &date);
486 if(FAILED(hres))
487 return hres;
489 hres = create_builtin_function(ctx, DateConstr_value, PROPF_CONSTR, date, ret);
491 jsdisp_release(date);
492 return hres;