2 * Copyright 2008 Jacek Caban for CodeWeavers
3 * Copyright 2009 Piotr Caban
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
33 /* 1601 to 1970 is 369 years plus 89 leap days */
34 #define TIME_EPOCH ((ULONGLONG)(369 * 365 + 89) * 86400 * 1000)
39 /* ECMA-262 3rd Edition 15.9.1.1 */
43 SYSTEMTIME standardDate
;
45 SYSTEMTIME daylightDate
;
49 static const WCHAR toStringW
[] = {'t','o','S','t','r','i','n','g',0};
50 static const WCHAR toLocaleStringW
[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
51 static const WCHAR valueOfW
[] = {'v','a','l','u','e','O','f',0};
52 static const WCHAR toUTCStringW
[] = {'t','o','U','T','C','S','t','r','i','n','g',0};
53 static const WCHAR toGMTStringW
[] = {'t','o','G','M','T','S','t','r','i','n','g',0};
54 static const WCHAR toDateStringW
[] = {'t','o','D','a','t','e','S','t','r','i','n','g',0};
55 static const WCHAR toTimeStringW
[] = {'t','o','T','i','m','e','S','t','r','i','n','g',0};
56 static const WCHAR toLocaleDateStringW
[] = {'t','o','L','o','c','a','l','e','D','a','t','e','S','t','r','i','n','g',0};
57 static const WCHAR toLocaleTimeStringW
[] = {'t','o','L','o','c','a','l','e','T','i','m','e','S','t','r','i','n','g',0};
58 static const WCHAR getTimeW
[] = {'g','e','t','T','i','m','e',0};
59 static const WCHAR getFullYearW
[] = {'g','e','t','F','u','l','l','Y','e','a','r',0};
60 static const WCHAR getUTCFullYearW
[] = {'g','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
61 static const WCHAR getMonthW
[] = {'g','e','t','M','o','n','t','h',0};
62 static const WCHAR getUTCMonthW
[] = {'g','e','t','U','T','C','M','o','n','t','h',0};
63 static const WCHAR getDateW
[] = {'g','e','t','D','a','t','e',0};
64 static const WCHAR getUTCDateW
[] = {'g','e','t','U','T','C','D','a','t','e',0};
65 static const WCHAR getDayW
[] = {'g','e','t','D','a','y',0};
66 static const WCHAR getUTCDayW
[] = {'g','e','t','U','T','C','D','a','y',0};
67 static const WCHAR getHoursW
[] = {'g','e','t','H','o','u','r','s',0};
68 static const WCHAR getUTCHoursW
[] = {'g','e','t','U','T','C','H','o','u','r','s',0};
69 static const WCHAR getMinutesW
[] = {'g','e','t','M','i','n','u','t','e','s',0};
70 static const WCHAR getUTCMinutesW
[] = {'g','e','t','U','T','C','M','i','n','u','t','e','s',0};
71 static const WCHAR getSecondsW
[] = {'g','e','t','S','e','c','o','n','d','s',0};
72 static const WCHAR getUTCSecondsW
[] = {'g','e','t','U','T','C','S','e','c','o','n','d','s',0};
73 static const WCHAR getMillisecondsW
[] = {'g','e','t','M','i','l','l','i','s','e','c','o','n','d','s',0};
74 static const WCHAR getUTCMillisecondsW
[] = {'g','e','t','U','T','C','M','i','l','l','i','s','e','c','o','n','d','s',0};
75 static const WCHAR getTimezoneOffsetW
[] = {'g','e','t','T','i','m','e','z','o','n','e','O','f','f','s','e','t',0};
76 static const WCHAR setTimeW
[] = {'s','e','t','T','i','m','e',0};
77 static const WCHAR setMillisecondsW
[] = {'s','e','t','M','i','l','l','i','s','e','c','o','n','d','s',0};
78 static const WCHAR setUTCMillisecondsW
[] = {'s','e','t','U','T','C','M','i','l','l','i','s','e','c','o','n','d','s',0};
79 static const WCHAR setSecondsW
[] = {'s','e','t','S','e','c','o','n','d','s',0};
80 static const WCHAR setUTCSecondsW
[] = {'s','e','t','U','T','C','S','e','c','o','n','d','s',0};
81 static const WCHAR setMinutesW
[] = {'s','e','t','M','i','n','u','t','e','s',0};
82 static const WCHAR setUTCMinutesW
[] = {'s','e','t','U','T','C','M','i','n','u','t','e','s',0};
83 static const WCHAR setHoursW
[] = {'s','e','t','H','o','u','r','s',0};
84 static const WCHAR setUTCHoursW
[] = {'s','e','t','U','T','C','H','o','u','r','s',0};
85 static const WCHAR setDateW
[] = {'s','e','t','D','a','t','e',0};
86 static const WCHAR setUTCDateW
[] = {'s','e','t','U','T','C','D','a','t','e',0};
87 static const WCHAR setMonthW
[] = {'s','e','t','M','o','n','t','h',0};
88 static const WCHAR setUTCMonthW
[] = {'s','e','t','U','T','C','M','o','n','t','h',0};
89 static const WCHAR setFullYearW
[] = {'s','e','t','F','u','l','l','Y','e','a','r',0};
90 static const WCHAR setUTCFullYearW
[] = {'s','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
91 static const WCHAR getYearW
[] = {'g','e','t','Y','e','a','r',0};
92 static const WCHAR setYearW
[] = {'s','e','t','Y','e','a','r',0};
94 static const WCHAR UTCW
[] = {'U','T','C',0};
95 static const WCHAR parseW
[] = {'p','a','r','s','e',0};
97 static inline DateInstance
*date_from_jsdisp(jsdisp_t
*jsdisp
)
99 return CONTAINING_RECORD(jsdisp
, DateInstance
, dispex
);
102 static inline DateInstance
*date_this(vdisp_t
*jsthis
)
104 return is_vclass(jsthis
, JSCLASS_DATE
) ? date_from_jsdisp(jsthis
->u
.jsdisp
) : NULL
;
107 /*ECMA-262 3rd Edition 15.9.1.2 */
108 #define MS_PER_DAY 86400000
109 #define MS_PER_HOUR 3600000
110 #define MS_PER_MINUTE 60000
112 /* ECMA-262 3rd Edition 15.9.1.2 */
113 static inline DOUBLE
day(DOUBLE time
)
115 return floor(time
/ MS_PER_DAY
);
118 /* ECMA-262 3rd Edition 15.9.1.2 */
119 static inline DOUBLE
time_within_day(DOUBLE time
)
123 ret
= fmod(time
, MS_PER_DAY
);
130 /* ECMA-262 3rd Edition 15.9.1.3 */
131 static inline DOUBLE
days_in_year(DOUBLE year
)
135 if(year
!= (int)year
)
139 if(y
%4 != 0) return 365;
140 if(y
%100 != 0) return 366;
141 if(y
%400 != 0) return 365;
145 /* ECMA-262 3rd Edition 15.9.1.3 */
146 static inline DOUBLE
day_from_year(DOUBLE year
)
148 if(year
!= (int)year
)
151 return floor(365.0*(year
-1970) + floor((year
-1969)/4)
152 - floor((year
-1901)/100) + floor((year
-1601)/400));
155 static inline int day_from_month(int month
, int in_leap_year
)
164 return 59+in_leap_year
;
166 return 90+in_leap_year
;
168 return 120+in_leap_year
;
170 return 151+in_leap_year
;
172 return 181+in_leap_year
;
174 return 212+in_leap_year
;
176 return 243+in_leap_year
;
178 return 273+in_leap_year
;
180 return 304+in_leap_year
;
182 return 334+in_leap_year
;
186 /* ECMA-262 3rd Edition 15.9.1.3 */
187 static inline DOUBLE
time_from_year(DOUBLE year
)
189 return MS_PER_DAY
*day_from_year(year
);
192 /* ECMA-262 3rd Edition 15.9.1.3 */
193 static inline DOUBLE
year_from_time(DOUBLE time
)
200 y
= 1970 + time
/365.25/MS_PER_DAY
;
202 if(time_from_year(y
) > time
)
203 while(time_from_year(y
) > time
) y
--;
205 while(time_from_year(y
+1)<=time
) y
++;
210 /* ECMA-262 3rd Edition 15.9.1.3 */
211 static inline int in_leap_year(DOUBLE time
)
213 if(days_in_year(year_from_time(time
))==366)
218 /* ECMA-262 3rd Edition 15.9.1.4 */
219 static inline int day_within_year(DOUBLE time
)
221 return day(time
) - day_from_year(year_from_time(time
));
224 /* ECMA-262 3rd Edition 15.9.1.4 */
225 static inline DOUBLE
month_from_time(DOUBLE time
)
227 int ily
= in_leap_year(time
);
228 int dwy
= day_within_year(time
);
233 if(0<=dwy
&& dwy
<31) return 0;
234 if(dwy
< 59+ily
) return 1;
235 if(dwy
< 90+ily
) return 2;
236 if(dwy
< 120+ily
) return 3;
237 if(dwy
< 151+ily
) return 4;
238 if(dwy
< 181+ily
) return 5;
239 if(dwy
< 212+ily
) return 6;
240 if(dwy
< 243+ily
) return 7;
241 if(dwy
< 273+ily
) return 8;
242 if(dwy
< 304+ily
) return 9;
243 if(dwy
< 334+ily
) return 10;
247 /* ECMA-262 3rd Edition 15.9.1.5 */
248 static inline DOUBLE
date_from_time(DOUBLE time
)
250 int dwy
= day_within_year(time
);
251 int ily
= in_leap_year(time
);
252 int mft
= month_from_time(time
);
257 if(mft
==0) return dwy
+1;
258 if(mft
==1) return dwy
-30;
259 if(mft
==2) return dwy
-58-ily
;
260 if(mft
==3) return dwy
-89-ily
;
261 if(mft
==4) return dwy
-119-ily
;
262 if(mft
==5) return dwy
-150-ily
;
263 if(mft
==6) return dwy
-180-ily
;
264 if(mft
==7) return dwy
-211-ily
;
265 if(mft
==8) return dwy
-242-ily
;
266 if(mft
==9) return dwy
-272-ily
;
267 if(mft
==10) return dwy
-303-ily
;
271 /* ECMA-262 3rd Edition 15.9.1.6 */
272 static inline DOUBLE
week_day(DOUBLE time
)
279 ret
= fmod(day(time
)+4, 7);
285 static inline DOUBLE
convert_time(int year
, SYSTEMTIME st
)
296 time
= time_from_year(year
);
297 time
+= (DOUBLE
)day_from_month(st
.wMonth
-1, in_leap_year(time
)) * MS_PER_DAY
;
300 set_week_day
= st
.wDayOfWeek
-week_day(time
);
303 time
+= set_week_day
* MS_PER_DAY
;
305 time
+= (DOUBLE
)(st
.wDay
-1) * 7 * MS_PER_DAY
;
306 if(month_from_time(time
) != st
.wMonth
-1)
307 time
-= 7 * MS_PER_DAY
;
310 time
+= st
.wDay
* MS_PER_DAY
;
312 time
+= st
.wHour
* MS_PER_HOUR
;
313 time
+= st
.wMinute
* MS_PER_MINUTE
;
318 /* ECMA-262 3rd Edition 15.9.1.9 */
319 static inline DOUBLE
daylight_saving_ta(DOUBLE time
, DateInstance
*date
)
321 int year
= year_from_time(time
);
322 DOUBLE standardTime
, daylightTime
;
327 standardTime
= convert_time(year
, date
->standardDate
);
328 daylightTime
= convert_time(year
, date
->daylightDate
);
330 if(isnan(standardTime
) || isnan(daylightTime
))
332 else if(standardTime
> daylightTime
) {
333 if(daylightTime
<= time
&& time
< standardTime
)
334 return date
->daylightBias
;
336 return date
->standardBias
;
339 if(standardTime
<= time
&& time
< daylightTime
)
340 return date
->standardBias
;
342 return date
->daylightBias
;
346 /* ECMA-262 3rd Edition 15.9.1.9 */
347 static inline DOUBLE
local_time(DOUBLE time
, DateInstance
*date
)
349 return time
- (daylight_saving_ta(time
, date
)+date
->bias
)*MS_PER_MINUTE
;
352 /* ECMA-262 3rd Edition 15.9.1.9 */
353 static inline DOUBLE
utc(DOUBLE time
, DateInstance
*date
)
355 time
+= date
->bias
* MS_PER_MINUTE
;
356 return time
+ daylight_saving_ta(time
, date
)*MS_PER_MINUTE
;
359 /* ECMA-262 3rd Edition 15.9.1.10 */
360 static inline DOUBLE
hour_from_time(DOUBLE time
)
367 ret
= fmod(floor(time
/MS_PER_HOUR
), 24);
373 /* ECMA-262 3rd Edition 15.9.1.10 */
374 static inline DOUBLE
min_from_time(DOUBLE time
)
381 ret
= fmod(floor(time
/MS_PER_MINUTE
), 60);
387 /* ECMA-262 3rd Edition 15.9.1.10 */
388 static inline DOUBLE
sec_from_time(DOUBLE time
)
395 ret
= fmod(floor(time
/1000), 60);
401 /* ECMA-262 3rd Edition 15.9.1.10 */
402 static inline DOUBLE
ms_from_time(DOUBLE time
)
409 ret
= fmod(time
, 1000);
410 if(ret
<0) ret
+= 1000;
415 /* ECMA-262 3rd Edition 15.9.1.11 */
416 static inline DOUBLE
make_time(DOUBLE hour
, DOUBLE min
, DOUBLE sec
, DOUBLE ms
)
418 return hour
*MS_PER_HOUR
+ min
*MS_PER_MINUTE
+ sec
*1000 + ms
;
421 /* ECMA-262 3rd Edition 15.9.1.12 */
422 static inline DOUBLE
make_day(DOUBLE year
, DOUBLE month
, DOUBLE day
)
426 year
+= floor(month
/12);
428 month
= fmod(month
, 12);
429 if(month
<0) month
+= 12;
431 time
= time_from_year(year
);
433 day
+= floor(time
/ MS_PER_DAY
);
434 day
+= day_from_month(month
, in_leap_year(time
));
439 /* ECMA-262 3rd Edition 15.9.1.13 */
440 static inline DOUBLE
make_date(DOUBLE day
, DOUBLE time
)
442 return day
*MS_PER_DAY
+ time
;
445 /* ECMA-262 3rd Edition 15.9.1.14 */
446 static inline DOUBLE
time_clip(DOUBLE time
)
448 if(8.64e15
< time
|| time
< -8.64e15
) {
455 static SYSTEMTIME
create_systemtime(DOUBLE time
)
459 st
.wYear
= year_from_time(time
);
460 st
.wMonth
= month_from_time(time
) + 1;
461 st
.wDayOfWeek
= week_day(time
);
462 st
.wDay
= date_from_time(time
);
463 st
.wHour
= hour_from_time(time
);
464 st
.wMinute
= min_from_time(time
);
465 st
.wSecond
= sec_from_time(time
);
466 st
.wMilliseconds
= ms_from_time(time
);
471 static inline HRESULT
date_to_string(DOUBLE time
, BOOL show_offset
, int offset
, jsval_t
*r
)
473 static const WCHAR formatW
[] = { '%','s',' ','%','s',' ','%','d',' ',
474 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
475 'U','T','C','%','c','%','0','2','d','%','0','2','d',' ','%','d','%','s',0 };
476 static const WCHAR formatUTCW
[] = { '%','s',' ','%','s',' ','%','d',' ',
477 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
478 'U','T','C',' ','%','d','%','s',0 };
479 static const WCHAR formatNoOffsetW
[] = { '%','s',' ','%','s',' ',
480 '%','d',' ','%','0','2','d',':','%','0','2','d',':',
481 '%','0','2','d',' ','%','d','%','s',0 };
482 static const WCHAR ADW
[] = { 0 };
483 static const WCHAR BCW
[] = { ' ','B','.','C','.',0 };
485 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
486 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
487 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
488 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
489 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
490 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
491 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
492 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
493 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
495 BOOL formatAD
= TRUE
;
496 WCHAR week
[64], month
[64];
505 *r
= jsval_string(jsstr_nan());
510 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
513 GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(time
)], week
, sizeof(week
)/sizeof(*week
));
516 GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(time
)], month
, sizeof(month
)/sizeof(*month
));
518 year
= year_from_time(time
);
524 day
= date_from_time(time
);
532 sprintfW(buf
, formatNoOffsetW
, week
, month
, day
,
533 (int)hour_from_time(time
), (int)min_from_time(time
),
534 (int)sec_from_time(time
), year
, formatAD
?ADW
:BCW
);
536 sprintfW(buf
, formatW
, week
, month
, day
,
537 (int)hour_from_time(time
), (int)min_from_time(time
),
538 (int)sec_from_time(time
), sign
, offset
/60, offset
%60,
539 year
, formatAD
?ADW
:BCW
);
541 sprintfW(buf
, formatUTCW
, week
, month
, day
,
542 (int)hour_from_time(time
), (int)min_from_time(time
),
543 (int)sec_from_time(time
), year
, formatAD
?ADW
:BCW
);
545 date_jsstr
= jsstr_alloc(buf
);
547 return E_OUTOFMEMORY
;
549 *r
= jsval_string(date_jsstr
);
554 /* ECMA-262 3rd Edition 15.9.1.2 */
555 static HRESULT
dateobj_to_string(DateInstance
*date
, jsval_t
*r
)
560 time
= local_time(date
->time
, date
);
561 offset
= date
->bias
+
562 daylight_saving_ta(time
, date
);
564 return date_to_string(time
, TRUE
, offset
, r
);
567 static HRESULT
Date_toString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
573 if(!(date
= date_this(jsthis
)))
574 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
576 return dateobj_to_string(date
, r
);
579 /* ECMA-262 3rd Edition 15.9.1.5 */
580 static HRESULT
Date_toLocaleString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
586 int date_len
, time_len
;
590 if(!(date
= date_this(jsthis
)))
591 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
593 if(isnan(date
->time
)) {
595 *r
= jsval_string(jsstr_nan());
599 st
= create_systemtime(local_time(date
->time
, date
));
601 if(st
.wYear
<1601 || st
.wYear
>9999)
602 return dateobj_to_string(date
, r
);
607 date_len
= GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, NULL
, 0);
608 time_len
= GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, NULL
, 0);
610 date_str
= jsstr_alloc_buf(date_len
+time_len
-1, &ptr
);
612 return E_OUTOFMEMORY
;
614 GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, ptr
, date_len
);
615 GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, ptr
+date_len
, time_len
);
616 ptr
[date_len
-1] = ' ';
618 *r
= jsval_string(date_str
);
623 static HRESULT
Date_valueOf(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
630 if(!(date
= date_this(jsthis
)))
631 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
634 *r
= jsval_number(date
->time
);
638 static inline HRESULT
create_utc_string(script_ctx_t
*ctx
, vdisp_t
*jsthis
, jsval_t
*r
)
640 static const WCHAR formatADW
[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ',
641 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
642 static const WCHAR formatBCW
[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ','B','.','C','.',' ',
643 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
645 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
646 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
647 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
648 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
649 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
650 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
651 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
652 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
653 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
655 BOOL formatAD
= TRUE
;
656 WCHAR week
[64], month
[64];
663 if(!(date
= date_this(jsthis
)))
664 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
666 if(isnan(date
->time
)) {
668 *r
= jsval_string(jsstr_nan());
673 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
676 GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(date
->time
)], week
, sizeof(week
)/sizeof(*week
));
679 GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(date
->time
)], month
, sizeof(month
)/sizeof(*month
));
681 year
= year_from_time(date
->time
);
687 day
= date_from_time(date
->time
);
689 sprintfW(buf
, formatAD
? formatADW
: formatBCW
, week
, day
, month
, year
,
690 (int)hour_from_time(date
->time
), (int)min_from_time(date
->time
),
691 (int)sec_from_time(date
->time
));
693 date_str
= jsstr_alloc(buf
);
695 return E_OUTOFMEMORY
;
697 *r
= jsval_string(date_str
);
702 /* ECMA-262 3rd Edition 15.9.5.42 */
703 static HRESULT
Date_toUTCString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
707 return create_utc_string(ctx
, jsthis
, r
);
710 static HRESULT
Date_toGMTString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
714 return create_utc_string(ctx
, jsthis
, r
);
717 /* ECMA-262 3rd Edition 15.9.5.3 */
718 static HRESULT
dateobj_to_date_string(DateInstance
*date
, jsval_t
*r
)
720 static const WCHAR formatADW
[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',0 };
721 static const WCHAR formatBCW
[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',' ','B','.','C','.',0 };
723 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
724 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
725 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
726 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
727 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
728 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
729 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
730 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
731 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
733 BOOL formatAD
= TRUE
;
734 WCHAR week
[64], month
[64];
741 if(isnan(date
->time
)) {
743 *r
= jsval_string(jsstr_nan());
747 time
= local_time(date
->time
, date
);
750 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
753 GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(time
)], week
, sizeof(week
)/sizeof(*week
));
756 GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(time
)], month
, sizeof(month
)/sizeof(*month
));
758 year
= year_from_time(time
);
764 day
= date_from_time(time
);
766 sprintfW(buf
, formatAD
? formatADW
: formatBCW
, week
, month
, day
, year
);
768 date_str
= jsstr_alloc(buf
);
770 return E_OUTOFMEMORY
;
772 *r
= jsval_string(date_str
);
777 static HRESULT
Date_toDateString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
782 if(!(date
= date_this(jsthis
)))
783 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
785 return dateobj_to_date_string(date
, r
);
788 /* ECMA-262 3rd Edition 15.9.5.4 */
789 static HRESULT
Date_toTimeString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
792 static const WCHAR formatW
[] = { '%','0','2','d',':','%','0','2','d',':','%','0','2','d',
793 ' ','U','T','C','%','c','%','0','2','d','%','0','2','d',0 };
794 static const WCHAR formatUTCW
[] = { '%','0','2','d',':','%','0','2','d',
795 ':','%','0','2','d',' ','U','T','C',0 };
805 if(!(date
= date_this(jsthis
)))
806 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
808 if(isnan(date
->time
)) {
810 *r
= jsval_string(jsstr_nan());
814 time
= local_time(date
->time
, date
);
817 offset
= date
->bias
+
818 daylight_saving_ta(time
, date
);
827 sprintfW(buf
, formatW
, (int)hour_from_time(time
),
828 (int)min_from_time(time
), (int)sec_from_time(time
),
829 sign
, offset
/60, offset
%60);
831 sprintfW(buf
, formatUTCW
, (int)hour_from_time(time
),
832 (int)min_from_time(time
), (int)sec_from_time(time
));
834 date_str
= jsstr_alloc(buf
);
836 return E_OUTOFMEMORY
;
838 *r
= jsval_string(date_str
);
843 /* ECMA-262 3rd Edition 15.9.5.6 */
844 static HRESULT
Date_toLocaleDateString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
854 if(!(date
= date_this(jsthis
)))
855 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
857 if(isnan(date
->time
)) {
859 *r
= jsval_string(jsstr_nan());
863 st
= create_systemtime(local_time(date
->time
, date
));
865 if(st
.wYear
<1601 || st
.wYear
>9999)
866 return dateobj_to_date_string(date
, r
);
871 len
= GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, NULL
, 0);
872 date_str
= jsstr_alloc_buf(len
-1, &ptr
);
874 return E_OUTOFMEMORY
;
875 GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, ptr
, len
);
877 *r
= jsval_string(date_str
);
882 /* ECMA-262 3rd Edition 15.9.5.7 */
883 static HRESULT
Date_toLocaleTimeString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
893 if(!(date
= date_this(jsthis
)))
894 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
896 if(isnan(date
->time
)) {
898 *r
= jsval_string(jsstr_nan());
902 st
= create_systemtime(local_time(date
->time
, date
));
904 if(st
.wYear
<1601 || st
.wYear
>9999)
905 return Date_toTimeString(ctx
, jsthis
, flags
, argc
, argv
, r
);
910 len
= GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, NULL
, 0);
911 date_str
= jsstr_alloc_buf(len
-1, &ptr
);
913 return E_OUTOFMEMORY
;
914 GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, ptr
, len
);
916 *r
= jsval_string(date_str
);
921 /* ECMA-262 3rd Edition 15.9.5.9 */
922 static HRESULT
Date_getTime(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
929 if(!(date
= date_this(jsthis
)))
930 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
933 *r
= jsval_number(date
->time
);
937 /* ECMA-262 3rd Edition 15.9.5.10 */
938 static HRESULT
Date_getFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
945 if(!(date
= date_this(jsthis
)))
946 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
949 DOUBLE time
= local_time(date
->time
, date
);
951 *r
= jsval_number(year_from_time(time
));
956 /* ECMA-262 3rd Edition 15.9.5.11 */
957 static HRESULT
Date_getUTCFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
964 if(!(date
= date_this(jsthis
)))
965 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
968 *r
= jsval_number(year_from_time(date
->time
));
972 /* ECMA-262 3rd Edition 15.9.5.12 */
973 static HRESULT
Date_getMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
979 if(!(date
= date_this(jsthis
)))
980 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
983 *r
= jsval_number(month_from_time(local_time(date
->time
, date
)));
987 /* ECMA-262 3rd Edition 15.9.5.13 */
988 static HRESULT
Date_getUTCMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
995 if(!(date
= date_this(jsthis
)))
996 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
999 *r
= jsval_number(month_from_time(date
->time
));
1003 /* ECMA-262 3rd Edition 15.9.5.14 */
1004 static HRESULT
Date_getDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1010 if(!(date
= date_this(jsthis
)))
1011 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1014 *r
= jsval_number(date_from_time(local_time(date
->time
, date
)));
1018 /* ECMA-262 3rd Edition 15.9.5.15 */
1019 static HRESULT
Date_getUTCDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1026 if(!(date
= date_this(jsthis
)))
1027 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1030 *r
= jsval_number(date_from_time(date
->time
));
1034 /* ECMA-262 3rd Edition 15.9.5.16 */
1035 static HRESULT
Date_getDay(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1042 if(!(date
= date_this(jsthis
)))
1043 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1046 *r
= jsval_number(week_day(local_time(date
->time
, date
)));
1050 /* ECMA-262 3rd Edition 15.9.5.17 */
1051 static HRESULT
Date_getUTCDay(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1058 if(!(date
= date_this(jsthis
)))
1059 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1062 *r
= jsval_number(week_day(date
->time
));
1066 /* ECMA-262 3rd Edition 15.9.5.18 */
1067 static HRESULT
Date_getHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1074 if(!(date
= date_this(jsthis
)))
1075 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1078 *r
= jsval_number(hour_from_time(local_time(date
->time
, date
)));
1082 /* ECMA-262 3rd Edition 15.9.5.19 */
1083 static HRESULT
Date_getUTCHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1090 if(!(date
= date_this(jsthis
)))
1091 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1094 *r
= jsval_number(hour_from_time(date
->time
));
1098 /* ECMA-262 3rd Edition 15.9.5.20 */
1099 static HRESULT
Date_getMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1106 if(!(date
= date_this(jsthis
)))
1107 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1110 *r
= jsval_number(min_from_time(local_time(date
->time
, date
)));
1114 /* ECMA-262 3rd Edition 15.9.5.21 */
1115 static HRESULT
Date_getUTCMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1122 if(!(date
= date_this(jsthis
)))
1123 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1126 *r
= jsval_number(min_from_time(date
->time
));
1130 /* ECMA-262 3rd Edition 15.9.5.22 */
1131 static HRESULT
Date_getSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1137 if(!(date
= date_this(jsthis
)))
1138 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1141 *r
= jsval_number(sec_from_time(local_time(date
->time
, date
)));
1145 /* ECMA-262 3rd Edition 15.9.5.23 */
1146 static HRESULT
Date_getUTCSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1153 if(!(date
= date_this(jsthis
)))
1154 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1157 *r
= jsval_number(sec_from_time(date
->time
));
1161 /* ECMA-262 3rd Edition 15.9.5.24 */
1162 static HRESULT
Date_getMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1169 if(!(date
= date_this(jsthis
)))
1170 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1173 *r
= jsval_number(ms_from_time(local_time(date
->time
, date
)));
1177 /* ECMA-262 3rd Edition 15.9.5.25 */
1178 static HRESULT
Date_getUTCMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1185 if(!(date
= date_this(jsthis
)))
1186 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1189 *r
= jsval_number(ms_from_time(date
->time
));
1193 /* ECMA-262 3rd Edition 15.9.5.26 */
1194 static HRESULT
Date_getTimezoneOffset(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1201 if(!(date
= date_this(jsthis
)))
1202 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1205 *r
= jsval_number(floor((date
->time
-local_time(date
->time
, date
))/MS_PER_MINUTE
));
1209 /* ECMA-262 3rd Edition 15.9.5.27 */
1210 static HRESULT
Date_setTime(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1219 if(!(date
= date_this(jsthis
)))
1220 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1223 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1225 hres
= to_number(ctx
, argv
[0], &n
);
1229 date
->time
= time_clip(n
);
1232 *r
= jsval_number(date
->time
);
1236 /* ECMA-262 3rd Edition 15.9.5.28 */
1237 static HRESULT
Date_setMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1246 if(!(date
= date_this(jsthis
)))
1247 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1250 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1252 hres
= to_number(ctx
, argv
[0], &n
);
1256 t
= local_time(date
->time
, date
);
1257 t
= make_date(day(t
), make_time(hour_from_time(t
), min_from_time(t
),
1258 sec_from_time(t
), n
));
1259 date
->time
= time_clip(utc(t
, date
));
1262 *r
= jsval_number(date
->time
);
1266 /* ECMA-262 3rd Edition 15.9.5.29 */
1267 static HRESULT
Date_setUTCMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1276 if(!(date
= date_this(jsthis
)))
1277 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1280 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1282 hres
= to_number(ctx
, argv
[0], &n
);
1287 t
= make_date(day(t
), make_time(hour_from_time(t
), min_from_time(t
),
1288 sec_from_time(t
), n
));
1289 date
->time
= time_clip(t
);
1292 *r
= jsval_number(date
->time
);
1296 /* ECMA-262 3rd Edition 15.9.5.30 */
1297 static HRESULT
Date_setSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1306 if(!(date
= date_this(jsthis
)))
1307 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1310 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1312 t
= local_time(date
->time
, date
);
1314 hres
= to_number(ctx
, argv
[0], &sec
);
1319 hres
= to_number(ctx
, argv
[1], &ms
);
1323 ms
= ms_from_time(t
);
1326 t
= make_date(day(t
), make_time(hour_from_time(t
),
1327 min_from_time(t
), sec
, ms
));
1328 date
->time
= time_clip(utc(t
, date
));
1331 *r
= jsval_number(date
->time
);
1335 /* ECMA-262 3rd Edition 15.9.5.31 */
1336 static HRESULT
Date_setUTCSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1345 if(!(date
= date_this(jsthis
)))
1346 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1349 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1353 hres
= to_number(ctx
, argv
[0], &sec
);
1358 hres
= to_number(ctx
, argv
[1], &ms
);
1362 ms
= ms_from_time(t
);
1365 t
= make_date(day(t
), make_time(hour_from_time(t
),
1366 min_from_time(t
), sec
, ms
));
1367 date
->time
= time_clip(t
);
1370 *r
= jsval_number(date
->time
);
1374 /* ECMA-262 3rd Edition 15.9.5.33 */
1375 static HRESULT
Date_setMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1379 double t
, min
, sec
, ms
;
1384 if(!(date
= date_this(jsthis
)))
1385 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1388 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1390 t
= local_time(date
->time
, date
);
1392 hres
= to_number(ctx
, argv
[0], &min
);
1397 hres
= to_number(ctx
, argv
[1], &sec
);
1401 sec
= sec_from_time(t
);
1405 hres
= to_number(ctx
, argv
[2], &ms
);
1409 ms
= ms_from_time(t
);
1412 t
= make_date(day(t
), make_time(hour_from_time(t
),
1414 date
->time
= time_clip(utc(t
, date
));
1417 *r
= jsval_number(date
->time
);
1421 /* ECMA-262 3rd Edition 15.9.5.34 */
1422 static HRESULT
Date_setUTCMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1426 double t
, min
, sec
, ms
;
1431 if(!(date
= date_this(jsthis
)))
1432 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1435 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1439 hres
= to_number(ctx
, argv
[0], &min
);
1444 hres
= to_number(ctx
, argv
[1], &sec
);
1448 sec
= sec_from_time(t
);
1452 hres
= to_number(ctx
, argv
[2], &ms
);
1456 ms
= ms_from_time(t
);
1459 t
= make_date(day(t
), make_time(hour_from_time(t
),
1461 date
->time
= time_clip(t
);
1464 *r
= jsval_number(date
->time
);
1468 /* ECMA-262 3rd Edition 15.9.5.35 */
1469 static HRESULT
Date_setHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1473 double t
, hour
, min
, sec
, ms
;
1478 if(!(date
= date_this(jsthis
)))
1479 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1482 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1484 t
= local_time(date
->time
, date
);
1486 hres
= to_number(ctx
, argv
[0], &hour
);
1491 hres
= to_number(ctx
, argv
[1], &min
);
1495 min
= min_from_time(t
);
1499 hres
= to_number(ctx
, argv
[2], &sec
);
1503 sec
= sec_from_time(t
);
1507 hres
= to_number(ctx
, argv
[3], &ms
);
1511 ms
= ms_from_time(t
);
1514 t
= make_date(day(t
), make_time(hour
, min
, sec
, ms
));
1515 date
->time
= time_clip(utc(t
, date
));
1518 *r
= jsval_number(date
->time
);
1522 /* ECMA-262 3rd Edition 15.9.5.36 */
1523 static HRESULT
Date_setUTCHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1527 double t
, hour
, min
, sec
, ms
;
1532 if(!(date
= date_this(jsthis
)))
1533 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1536 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1540 hres
= to_number(ctx
, argv
[0], &hour
);
1545 hres
= to_number(ctx
, argv
[1], &min
);
1549 min
= min_from_time(t
);
1553 hres
= to_number(ctx
, argv
[2], &sec
);
1557 sec
= sec_from_time(t
);
1561 hres
= to_number(ctx
, argv
[3], &ms
);
1565 ms
= ms_from_time(t
);
1568 t
= make_date(day(t
), make_time(hour
, min
, sec
, ms
));
1569 date
->time
= time_clip(t
);
1572 *r
= jsval_number(date
->time
);
1576 /* ECMA-262 3rd Edition 15.9.5.36 */
1577 static HRESULT
Date_setDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1586 if(!(date
= date_this(jsthis
)))
1587 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1590 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1592 hres
= to_number(ctx
, argv
[0], &n
);
1596 t
= local_time(date
->time
, date
);
1597 t
= make_date(make_day(year_from_time(t
), month_from_time(t
), n
), time_within_day(t
));
1598 date
->time
= time_clip(utc(t
, date
));
1601 *r
= jsval_number(date
->time
);
1605 /* ECMA-262 3rd Edition 15.9.5.37 */
1606 static HRESULT
Date_setUTCDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1615 if(!(date
= date_this(jsthis
)))
1616 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1619 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1621 hres
= to_number(ctx
, argv
[0], &n
);
1626 t
= make_date(make_day(year_from_time(t
), month_from_time(t
), n
), time_within_day(t
));
1627 date
->time
= time_clip(t
);
1630 *r
= jsval_number(date
->time
);
1634 /* ECMA-262 3rd Edition 15.9.5.38 */
1635 static HRESULT
Date_setMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1639 DOUBLE t
, month
, ddate
;
1644 if(!(date
= date_this(jsthis
)))
1645 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1648 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1650 t
= local_time(date
->time
, date
);
1652 hres
= to_number(ctx
, argv
[0], &month
);
1657 hres
= to_number(ctx
, argv
[1], &ddate
);
1661 ddate
= date_from_time(t
);
1664 t
= make_date(make_day(year_from_time(t
), month
, ddate
),
1665 time_within_day(t
));
1666 date
->time
= time_clip(utc(t
, date
));
1669 *r
= jsval_number(date
->time
);
1673 /* ECMA-262 3rd Edition 15.9.5.39 */
1674 static HRESULT
Date_setUTCMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1678 double t
, month
, ddate
;
1683 if(!(date
= date_this(jsthis
)))
1684 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1687 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1691 hres
= to_number(ctx
, argv
[0], &month
);
1696 hres
= to_number(ctx
, argv
[1], &ddate
);
1700 ddate
= date_from_time(t
);
1703 t
= make_date(make_day(year_from_time(t
), month
, ddate
),
1704 time_within_day(t
));
1705 date
->time
= time_clip(t
);
1708 *r
= jsval_number(date
->time
);
1712 /* ECMA-262 3rd Edition 15.9.5.40 */
1713 static HRESULT
Date_setFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1717 double t
, year
, month
, ddate
;
1722 if(!(date
= date_this(jsthis
)))
1723 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1726 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1728 t
= local_time(date
->time
, date
);
1730 hres
= to_number(ctx
, argv
[0], &year
);
1735 hres
= to_number(ctx
, argv
[1], &month
);
1739 month
= month_from_time(t
);
1743 hres
= to_number(ctx
, argv
[2], &ddate
);
1747 ddate
= date_from_time(t
);
1750 t
= make_date(make_day(year
, month
, ddate
), time_within_day(t
));
1751 date
->time
= time_clip(utc(t
, date
));
1754 *r
= jsval_number(date
->time
);
1758 /* ECMA-262 3rd Edition 15.9.5.41 */
1759 static HRESULT
Date_setUTCFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1763 double t
, year
, month
, ddate
;
1768 if(!(date
= date_this(jsthis
)))
1769 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1772 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1776 hres
= to_number(ctx
, argv
[0], &year
);
1781 hres
= to_number(ctx
, argv
[1], &month
);
1785 month
= month_from_time(t
);
1789 hres
= to_number(ctx
, argv
[2], &ddate
);
1793 ddate
= date_from_time(t
);
1796 t
= make_date(make_day(year
, month
, ddate
), time_within_day(t
));
1797 date
->time
= time_clip(t
);
1800 *r
= jsval_number(date
->time
);
1804 /* ECMA-262 3rd Edition B2.4 */
1805 static HRESULT
Date_getYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1813 if(!(date
= date_this(jsthis
)))
1814 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1816 t
= local_time(date
->time
, date
);
1819 *r
= jsval_number(NAN
);
1823 year
= year_from_time(t
);
1825 *r
= jsval_number((1900<=year
&& year
<2000)?year
-1900:year
);
1829 /* ECMA-262 3rd Edition B2.5 */
1830 static HRESULT
Date_setYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1839 if(!(date
= date_this(jsthis
)))
1840 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1843 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1845 t
= local_time(date
->time
, date
);
1847 hres
= to_number(ctx
, argv
[0], &year
);
1854 *r
= jsval_number(NAN
);
1858 year
= year
>= 0.0 ? floor(year
) : -floor(-year
);
1859 if(-1.0 < year
&& year
< 100.0)
1862 date
->time
= time_clip(utc(make_date(make_day(year
, month_from_time(t
), date_from_time(t
)), time_within_day(t
)), date
));
1865 *r
= jsval_number(date
->time
);
1869 static HRESULT
Date_get_value(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
1873 return dateobj_to_string(date_from_jsdisp(jsthis
), r
);
1876 static const builtin_prop_t Date_props
[] = {
1877 {getDateW
, Date_getDate
, PROPF_METHOD
},
1878 {getDayW
, Date_getDay
, PROPF_METHOD
},
1879 {getFullYearW
, Date_getFullYear
, PROPF_METHOD
},
1880 {getHoursW
, Date_getHours
, PROPF_METHOD
},
1881 {getMillisecondsW
, Date_getMilliseconds
, PROPF_METHOD
},
1882 {getMinutesW
, Date_getMinutes
, PROPF_METHOD
},
1883 {getMonthW
, Date_getMonth
, PROPF_METHOD
},
1884 {getSecondsW
, Date_getSeconds
, PROPF_METHOD
},
1885 {getTimeW
, Date_getTime
, PROPF_METHOD
},
1886 {getTimezoneOffsetW
, Date_getTimezoneOffset
, PROPF_METHOD
},
1887 {getUTCDateW
, Date_getUTCDate
, PROPF_METHOD
},
1888 {getUTCDayW
, Date_getUTCDay
, PROPF_METHOD
},
1889 {getUTCFullYearW
, Date_getUTCFullYear
, PROPF_METHOD
},
1890 {getUTCHoursW
, Date_getUTCHours
, PROPF_METHOD
},
1891 {getUTCMillisecondsW
, Date_getUTCMilliseconds
, PROPF_METHOD
},
1892 {getUTCMinutesW
, Date_getUTCMinutes
, PROPF_METHOD
},
1893 {getUTCMonthW
, Date_getUTCMonth
, PROPF_METHOD
},
1894 {getUTCSecondsW
, Date_getUTCSeconds
, PROPF_METHOD
},
1895 {getYearW
, Date_getYear
, PROPF_METHOD
},
1896 {setDateW
, Date_setDate
, PROPF_METHOD
|1},
1897 {setFullYearW
, Date_setFullYear
, PROPF_METHOD
|3},
1898 {setHoursW
, Date_setHours
, PROPF_METHOD
|4},
1899 {setMillisecondsW
, Date_setMilliseconds
, PROPF_METHOD
|1},
1900 {setMinutesW
, Date_setMinutes
, PROPF_METHOD
|3},
1901 {setMonthW
, Date_setMonth
, PROPF_METHOD
|2},
1902 {setSecondsW
, Date_setSeconds
, PROPF_METHOD
|2},
1903 {setTimeW
, Date_setTime
, PROPF_METHOD
|1},
1904 {setUTCDateW
, Date_setUTCDate
, PROPF_METHOD
|1},
1905 {setUTCFullYearW
, Date_setUTCFullYear
, PROPF_METHOD
|3},
1906 {setUTCHoursW
, Date_setUTCHours
, PROPF_METHOD
|4},
1907 {setUTCMillisecondsW
, Date_setUTCMilliseconds
, PROPF_METHOD
|1},
1908 {setUTCMinutesW
, Date_setUTCMinutes
, PROPF_METHOD
|3},
1909 {setUTCMonthW
, Date_setUTCMonth
, PROPF_METHOD
|2},
1910 {setUTCSecondsW
, Date_setUTCSeconds
, PROPF_METHOD
|2},
1911 {setYearW
, Date_setYear
, PROPF_METHOD
|1},
1912 {toDateStringW
, Date_toDateString
, PROPF_METHOD
},
1913 {toGMTStringW
, Date_toGMTString
, PROPF_METHOD
},
1914 {toLocaleDateStringW
, Date_toLocaleDateString
, PROPF_METHOD
},
1915 {toLocaleStringW
, Date_toLocaleString
, PROPF_METHOD
},
1916 {toLocaleTimeStringW
, Date_toLocaleTimeString
, PROPF_METHOD
},
1917 {toStringW
, Date_toString
, PROPF_METHOD
},
1918 {toTimeStringW
, Date_toTimeString
, PROPF_METHOD
},
1919 {toUTCStringW
, Date_toUTCString
, PROPF_METHOD
},
1920 {valueOfW
, Date_valueOf
, PROPF_METHOD
},
1923 static const builtin_info_t Date_info
= {
1925 {NULL
, NULL
,0, Date_get_value
},
1926 sizeof(Date_props
)/sizeof(*Date_props
),
1932 static const builtin_info_t DateInst_info
= {
1934 {NULL
, NULL
,0, Date_get_value
},
1940 static HRESULT
create_date(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
, DOUBLE time
, jsdisp_t
**ret
)
1944 TIME_ZONE_INFORMATION tzi
;
1946 GetTimeZoneInformation(&tzi
);
1948 date
= heap_alloc_zero(sizeof(DateInstance
));
1950 return E_OUTOFMEMORY
;
1952 if(object_prototype
)
1953 hres
= init_dispex(&date
->dispex
, ctx
, &Date_info
, object_prototype
);
1955 hres
= init_dispex_from_constr(&date
->dispex
, ctx
, &DateInst_info
, ctx
->date_constr
);
1962 date
->bias
= tzi
.Bias
;
1963 date
->standardDate
= tzi
.StandardDate
;
1964 date
->standardBias
= tzi
.StandardBias
;
1965 date
->daylightDate
= tzi
.DaylightDate
;
1966 date
->daylightBias
= tzi
.DaylightBias
;
1968 *ret
= &date
->dispex
;
1972 static inline HRESULT
date_parse(jsstr_t
*input_str
, double *ret
) {
1973 static const DWORD string_ids
[] = { LOCALE_SMONTHNAME12
, LOCALE_SMONTHNAME11
,
1974 LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME8
,
1975 LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME5
,
1976 LOCALE_SMONTHNAME4
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME2
,
1977 LOCALE_SMONTHNAME1
, LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
,
1978 LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
, LOCALE_SDAYNAME4
,
1979 LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
};
1980 WCHAR
*strings
[sizeof(string_ids
)/sizeof(DWORD
)];
1982 int input_len
, parse_len
= 0, nest_level
= 0, i
, size
;
1983 int year
= 0, month
= 0, day
= 0, hour
= 0, min
= 0, sec
= 0;
1984 int ms
= 0, offset
= 0, hour_adjust
= 0;
1985 BOOL set_year
= FALSE
, set_month
= FALSE
, set_day
= FALSE
, set_hour
= FALSE
;
1986 BOOL set_offset
= FALSE
, set_era
= FALSE
, ad
= TRUE
, set_am
= FALSE
, am
= TRUE
;
1987 BOOL set_hour_adjust
= TRUE
;
1988 TIME_ZONE_INFORMATION tzi
;
1993 input_len
= jsstr_length(input_str
);
1994 input
= jsstr_flatten(input_str
);
1996 return E_OUTOFMEMORY
;
1998 for(i
=0; i
<input_len
; i
++) {
1999 if(input
[i
] == '(') nest_level
++;
2000 else if(input
[i
] == ')') {
2007 else if(!nest_level
) parse_len
++;
2010 parse
= heap_alloc((parse_len
+1)*sizeof(WCHAR
));
2012 return E_OUTOFMEMORY
;
2015 for(i
=0; i
<input_len
; i
++) {
2016 if(input
[i
] == '(') nest_level
++;
2017 else if(input
[i
] == ')') nest_level
--;
2018 else if(!nest_level
) parse
[parse_len
++] = toupperW(input
[i
]);
2020 parse
[parse_len
] = 0;
2022 GetTimeZoneInformation(&tzi
);
2024 di
.standardDate
= tzi
.StandardDate
;
2025 di
.standardBias
= tzi
.StandardBias
;
2026 di
.daylightDate
= tzi
.DaylightDate
;
2027 di
.daylightBias
= tzi
.DaylightBias
;
2029 /* FIXME: Cache strings */
2030 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2031 for(i
=0; i
<sizeof(string_ids
)/sizeof(DWORD
); i
++) {
2032 size
= GetLocaleInfoW(lcid_en
, string_ids
[i
], NULL
, 0);
2033 strings
[i
] = heap_alloc((size
+1)*sizeof(WCHAR
));
2037 heap_free(strings
[i
]);
2039 return E_OUTOFMEMORY
;
2041 GetLocaleInfoW(lcid_en
, string_ids
[i
], strings
[i
], size
);
2044 for(i
=0; i
<parse_len
;) {
2045 while(isspaceW(parse
[i
])) i
++;
2046 if(parse
[i
] == ',') {
2047 while(parse
[i
] == ',') i
++;
2051 if(parse
[i
]>='0' && parse
[i
]<='9') {
2052 int tmp
= atoiW(&parse
[i
]);
2053 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2054 while(isspaceW(parse
[i
])) i
++;
2056 if(parse
[i
] == ':') {
2063 while(parse
[i
] == ':') i
++;
2064 while(isspaceW(parse
[i
])) i
++;
2065 if(parse
[i
]>='0' && parse
[i
]<='9') {
2066 min
= atoiW(&parse
[i
]);
2067 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2070 while(isspaceW(parse
[i
])) i
++;
2071 while(parse
[i
] == ':') i
++;
2072 while(isspaceW(parse
[i
])) i
++;
2073 if(parse
[i
]>='0' && parse
[i
]<='9') {
2074 sec
= atoiW(&parse
[i
]);
2075 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2078 else if(parse
[i
]=='-' || parse
[i
]=='/') {
2079 /* Short or long date */
2080 if(set_day
|| set_month
|| set_year
) break;
2087 while(isspaceW(parse
[i
])) i
++;
2088 while(parse
[i
]=='-' || parse
[i
]=='/') i
++;
2089 while(isspaceW(parse
[i
])) i
++;
2090 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2091 day
= atoiW(&parse
[i
]);
2092 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2094 while(parse
[i
]=='-' || parse
[i
]=='/') i
++;
2095 while(isspaceW(parse
[i
])) i
++;
2096 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2097 year
= atoiW(&parse
[i
]);
2098 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2107 else if(tmp
<0) break;
2121 else if(parse
[i
]=='+' || parse
[i
]=='-') {
2122 /* Timezone offset */
2123 BOOL positive
= TRUE
;
2125 if(set_offset
&& set_hour_adjust
) break;
2127 set_hour_adjust
= FALSE
;
2129 if(parse
[i
] == '-') positive
= FALSE
;
2132 while(isspaceW(parse
[i
])) i
++;
2133 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2134 offset
= atoiW(&parse
[i
]);
2135 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2137 if(offset
<24) offset
*= 60;
2138 else offset
= (offset
/100)*60 + offset
%100;
2140 if(positive
) offset
= -offset
;
2144 if(parse
[i
]<'A' || parse
[i
]>'Z') break;
2145 else if(parse
[i
]=='B' && (parse
[i
+1]=='C' ||
2146 (parse
[i
+1]=='.' && parse
[i
+2]=='C'))) {
2153 if(parse
[i
] == '.') i
++;
2155 if(parse
[i
] == '.') i
++;
2157 else if(parse
[i
]=='A' && (parse
[i
+1]=='D' ||
2158 (parse
[i
+1]=='.' && parse
[i
+2]=='D'))) {
2164 if(parse
[i
] == '.') i
++;
2166 if(parse
[i
] == '.') i
++;
2168 else if(parse
[i
+1]<'A' || parse
[i
+1]>'Z') {
2170 if(set_offset
) break;
2173 if(parse
[i
] <= 'I') hour_adjust
= parse
[i
]-'A'+2;
2174 else if(parse
[i
] == 'J') break;
2175 else if(parse
[i
] <= 'M') hour_adjust
= parse
[i
]-'K'+11;
2176 else if(parse
[i
] <= 'Y') hour_adjust
= parse
[i
]-'N';
2177 else hour_adjust
= 1;
2180 if(parse
[i
] == '.') i
++;
2182 else if(parse
[i
]=='A' && parse
[i
+1]=='M') {
2189 else if(parse
[i
]=='P' && parse
[i
+1]=='M') {
2196 else if((parse
[i
]=='U' && parse
[i
+1]=='T' && parse
[i
+2]=='C')
2197 || (parse
[i
]=='G' && parse
[i
+1]=='M' && parse
[i
+2]=='T')) {
2199 if(set_offset
) break;
2201 set_hour_adjust
= FALSE
;
2206 /* Month or garbage */
2209 for(size
=i
; parse
[size
]>='A' && parse
[size
]<='Z'; size
++);
2212 for(j
=0; j
<sizeof(string_ids
)/sizeof(DWORD
); j
++)
2213 if(!strncmpiW(&parse
[i
], strings
[j
], size
)) break;
2216 if(set_month
) break;
2220 else if(j
== sizeof(string_ids
)/sizeof(DWORD
)) break;
2227 if(i
== parse_len
&& set_year
&& set_month
&& set_day
&& (!set_am
|| hour
<13)) {
2229 if(hour
== 12) hour
= 0;
2233 if(!ad
) year
= -year
+1;
2234 else if(year
<100) year
+= 1900;
2236 *ret
= time_clip(make_date(make_day(year
, month
, day
),
2237 make_time(hour
+hour_adjust
, min
, sec
, ms
)) + offset
*MS_PER_MINUTE
);
2240 *ret
= utc(*ret
, &di
);
2245 for(i
=0; i
<sizeof(string_ids
)/sizeof(DWORD
); i
++)
2246 heap_free(strings
[i
]);
2252 static HRESULT
DateConstr_parse(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2263 *r
= jsval_number(NAN
);
2267 hres
= to_string(ctx
, argv
[0], &parse_str
);
2271 hres
= date_parse(parse_str
, &n
);
2272 jsstr_release(parse_str
);
2276 *r
= jsval_number(n
);
2280 static HRESULT
date_utc(script_ctx_t
*ctx
, unsigned argc
, jsval_t
*argv
, double *ret
)
2282 double year
, month
, vdate
, hours
, minutes
, seconds
, ms
;
2288 hres
= to_number(ctx
, argv
[0], &year
);
2291 if(0 <= year
&& year
<= 99)
2298 hres
= to_number(ctx
, argv
[1], &month
);
2306 hres
= to_number(ctx
, argv
[2], &vdate
);
2314 hres
= to_number(ctx
, argv
[3], &hours
);
2322 hres
= to_number(ctx
, argv
[4], &minutes
);
2330 hres
= to_number(ctx
, argv
[5], &seconds
);
2338 hres
= to_number(ctx
, argv
[6], &ms
);
2345 *ret
= time_clip(make_date(make_day(year
, month
, vdate
),
2346 make_time(hours
, minutes
,seconds
, ms
)));
2350 static HRESULT
DateConstr_UTC(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2358 hres
= date_utc(ctx
, argc
, argv
, &n
);
2359 if(SUCCEEDED(hres
) && r
)
2360 *r
= jsval_number(n
);
2364 static HRESULT
DateConstr_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2373 case DISPATCH_CONSTRUCT
:
2375 /* ECMA-262 3rd Edition 15.9.3.3 */
2380 GetSystemTimeAsFileTime(&time
);
2381 lltime
= ((LONGLONG
)time
.dwHighDateTime
<<32)
2382 + time
.dwLowDateTime
;
2384 hres
= create_date(ctx
, NULL
, lltime
/10000-TIME_EPOCH
, &date
);
2390 /* ECMA-262 3rd Edition 15.9.3.2 */
2395 hres
= to_primitive(ctx
, argv
[0], &prim
, NO_HINT
);
2400 hres
= date_parse(get_string(prim
), &n
);
2402 hres
= to_number(ctx
, prim
, &n
);
2404 jsval_release(prim
);
2408 hres
= create_date(ctx
, NULL
, time_clip(n
), &date
);
2414 /* ECMA-262 3rd Edition 15.9.3.1 */
2419 hres
= date_utc(ctx
, argc
, argv
, &ret_date
);
2423 hres
= create_date(ctx
, NULL
, ret_date
, &date
);
2427 di
= date_from_jsdisp(date
);
2428 di
->time
= utc(di
->time
, di
);
2432 *r
= jsval_obj(date
);
2436 FILETIME system_time
, local_time
;
2439 GetSystemTimeAsFileTime(&system_time
);
2440 FileTimeToLocalFileTime(&system_time
, &local_time
);
2441 lltime
= ((LONGLONG
)local_time
.dwHighDateTime
<<32)
2442 + local_time
.dwLowDateTime
;
2444 return date_to_string(lltime
/10000-TIME_EPOCH
, FALSE
, 0, r
);
2448 FIXME("unimplemented flags %x\n", flags
);
2455 static const builtin_prop_t DateConstr_props
[] = {
2456 {UTCW
, DateConstr_UTC
, PROPF_METHOD
},
2457 {parseW
, DateConstr_parse
, PROPF_METHOD
}
2460 static const builtin_info_t DateConstr_info
= {
2462 DEFAULT_FUNCTION_VALUE
,
2463 sizeof(DateConstr_props
)/sizeof(*DateConstr_props
),
2469 HRESULT
create_date_constr(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
, jsdisp_t
**ret
)
2474 static const WCHAR DateW
[] = {'D','a','t','e',0};
2476 hres
= create_date(ctx
, object_prototype
, 0.0, &date
);
2480 hres
= create_builtin_constructor(ctx
, DateConstr_value
, DateW
, &DateConstr_info
,
2481 PROPF_CONSTR
|7, date
, ret
);
2483 jsdisp_release(date
);