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 propertyIsEnumerableW
[] =
52 {'p','r','o','p','e','r','t','y','I','s','E','n','u','m','e','r','a','b','l','e',0};
53 static const WCHAR isPrototypeOfW
[] = {'i','s','P','r','o','t','o','t','y','p','e','O','f',0};
54 static const WCHAR valueOfW
[] = {'v','a','l','u','e','O','f',0};
55 static const WCHAR toUTCStringW
[] = {'t','o','U','T','C','S','t','r','i','n','g',0};
56 static const WCHAR toGMTStringW
[] = {'t','o','G','M','T','S','t','r','i','n','g',0};
57 static const WCHAR toDateStringW
[] = {'t','o','D','a','t','e','S','t','r','i','n','g',0};
58 static const WCHAR toTimeStringW
[] = {'t','o','T','i','m','e','S','t','r','i','n','g',0};
59 static const WCHAR toLocaleDateStringW
[] = {'t','o','L','o','c','a','l','e','D','a','t','e','S','t','r','i','n','g',0};
60 static const WCHAR toLocaleTimeStringW
[] = {'t','o','L','o','c','a','l','e','T','i','m','e','S','t','r','i','n','g',0};
61 static const WCHAR getTimeW
[] = {'g','e','t','T','i','m','e',0};
62 static const WCHAR getFullYearW
[] = {'g','e','t','F','u','l','l','Y','e','a','r',0};
63 static const WCHAR getUTCFullYearW
[] = {'g','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
64 static const WCHAR getMonthW
[] = {'g','e','t','M','o','n','t','h',0};
65 static const WCHAR getUTCMonthW
[] = {'g','e','t','U','T','C','M','o','n','t','h',0};
66 static const WCHAR getDateW
[] = {'g','e','t','D','a','t','e',0};
67 static const WCHAR getUTCDateW
[] = {'g','e','t','U','T','C','D','a','t','e',0};
68 static const WCHAR getDayW
[] = {'g','e','t','D','a','y',0};
69 static const WCHAR getUTCDayW
[] = {'g','e','t','U','T','C','D','a','y',0};
70 static const WCHAR getHoursW
[] = {'g','e','t','H','o','u','r','s',0};
71 static const WCHAR getUTCHoursW
[] = {'g','e','t','U','T','C','H','o','u','r','s',0};
72 static const WCHAR getMinutesW
[] = {'g','e','t','M','i','n','u','t','e','s',0};
73 static const WCHAR getUTCMinutesW
[] = {'g','e','t','U','T','C','M','i','n','u','t','e','s',0};
74 static const WCHAR getSecondsW
[] = {'g','e','t','S','e','c','o','n','d','s',0};
75 static const WCHAR getUTCSecondsW
[] = {'g','e','t','U','T','C','S','e','c','o','n','d','s',0};
76 static const WCHAR getMillisecondsW
[] = {'g','e','t','M','i','l','l','i','s','e','c','o','n','d','s',0};
77 static const WCHAR getUTCMillisecondsW
[] = {'g','e','t','U','T','C','M','i','l','l','i','s','e','c','o','n','d','s',0};
78 static const WCHAR getTimezoneOffsetW
[] = {'g','e','t','T','i','m','e','z','o','n','e','O','f','f','s','e','t',0};
79 static const WCHAR setTimeW
[] = {'s','e','t','T','i','m','e',0};
80 static const WCHAR setMillisecondsW
[] = {'s','e','t','M','i','l','l','i','s','e','c','o','n','d','s',0};
81 static const WCHAR setUTCMillisecondsW
[] = {'s','e','t','U','T','C','M','i','l','l','i','s','e','c','o','n','d','s',0};
82 static const WCHAR setSecondsW
[] = {'s','e','t','S','e','c','o','n','d','s',0};
83 static const WCHAR setUTCSecondsW
[] = {'s','e','t','U','T','C','S','e','c','o','n','d','s',0};
84 static const WCHAR setMinutesW
[] = {'s','e','t','M','i','n','u','t','e','s',0};
85 static const WCHAR setUTCMinutesW
[] = {'s','e','t','U','T','C','M','i','n','u','t','e','s',0};
86 static const WCHAR setHoursW
[] = {'s','e','t','H','o','u','r','s',0};
87 static const WCHAR setUTCHoursW
[] = {'s','e','t','U','T','C','H','o','u','r','s',0};
88 static const WCHAR setDateW
[] = {'s','e','t','D','a','t','e',0};
89 static const WCHAR setUTCDateW
[] = {'s','e','t','U','T','C','D','a','t','e',0};
90 static const WCHAR setMonthW
[] = {'s','e','t','M','o','n','t','h',0};
91 static const WCHAR setUTCMonthW
[] = {'s','e','t','U','T','C','M','o','n','t','h',0};
92 static const WCHAR setFullYearW
[] = {'s','e','t','F','u','l','l','Y','e','a','r',0};
93 static const WCHAR setUTCFullYearW
[] = {'s','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
94 static const WCHAR getYearW
[] = {'g','e','t','Y','e','a','r',0};
95 static const WCHAR setYearW
[] = {'s','e','t','Y','e','a','r',0};
97 static const WCHAR UTCW
[] = {'U','T','C',0};
98 static const WCHAR parseW
[] = {'p','a','r','s','e',0};
100 static inline DateInstance
*date_this(vdisp_t
*jsthis
)
102 return is_vclass(jsthis
, JSCLASS_DATE
) ? (DateInstance
*)jsthis
->u
.jsdisp
: NULL
;
105 /*ECMA-262 3rd Edition 15.9.1.2 */
106 #define MS_PER_DAY 86400000
107 #define MS_PER_HOUR 3600000
108 #define MS_PER_MINUTE 60000
110 /* ECMA-262 3rd Edition 15.9.1.2 */
111 static inline DOUBLE
day(DOUBLE time
)
113 return floor(time
/ MS_PER_DAY
);
116 /* ECMA-262 3rd Edition 15.9.1.2 */
117 static inline DOUBLE
time_within_day(DOUBLE time
)
121 ret
= fmod(time
, MS_PER_DAY
);
128 /* ECMA-262 3rd Edition 15.9.1.3 */
129 static inline DOUBLE
days_in_year(DOUBLE year
)
133 if(year
!= (int)year
)
137 if(y
%4 != 0) return 365;
138 if(y
%100 != 0) return 366;
139 if(y
%400 != 0) return 365;
143 /* ECMA-262 3rd Edition 15.9.1.3 */
144 static inline DOUBLE
day_from_year(DOUBLE year
)
146 if(year
!= (int)year
)
149 return floor(365.0*(year
-1970) + floor((year
-1969)/4)
150 - floor((year
-1901)/100) + floor((year
-1601)/400));
153 static inline int day_from_month(int month
, int in_leap_year
)
162 return 59+in_leap_year
;
164 return 90+in_leap_year
;
166 return 120+in_leap_year
;
168 return 151+in_leap_year
;
170 return 181+in_leap_year
;
172 return 212+in_leap_year
;
174 return 243+in_leap_year
;
176 return 273+in_leap_year
;
178 return 304+in_leap_year
;
180 return 334+in_leap_year
;
184 /* ECMA-262 3rd Edition 15.9.1.3 */
185 static inline DOUBLE
time_from_year(DOUBLE year
)
187 return MS_PER_DAY
*day_from_year(year
);
190 /* ECMA-262 3rd Edition 15.9.1.3 */
191 static inline DOUBLE
year_from_time(DOUBLE time
)
198 y
= 1970 + time
/365.25/MS_PER_DAY
;
200 if(time_from_year(y
) > time
)
201 while(time_from_year(y
) > time
) y
--;
203 while(time_from_year(y
+1)<=time
) y
++;
208 /* ECMA-262 3rd Edition 15.9.1.3 */
209 static inline int in_leap_year(DOUBLE time
)
211 if(days_in_year(year_from_time(time
))==366)
216 /* ECMA-262 3rd Edition 15.9.1.4 */
217 static inline int day_within_year(DOUBLE time
)
219 return day(time
) - day_from_year(year_from_time(time
));
222 /* ECMA-262 3rd Edition 15.9.1.4 */
223 static inline DOUBLE
month_from_time(DOUBLE time
)
225 int ily
= in_leap_year(time
);
226 int dwy
= day_within_year(time
);
231 if(0<=dwy
&& dwy
<31) return 0;
232 if(dwy
< 59+ily
) return 1;
233 if(dwy
< 90+ily
) return 2;
234 if(dwy
< 120+ily
) return 3;
235 if(dwy
< 151+ily
) return 4;
236 if(dwy
< 181+ily
) return 5;
237 if(dwy
< 212+ily
) return 6;
238 if(dwy
< 243+ily
) return 7;
239 if(dwy
< 273+ily
) return 8;
240 if(dwy
< 304+ily
) return 9;
241 if(dwy
< 334+ily
) return 10;
245 /* ECMA-262 3rd Edition 15.9.1.5 */
246 static inline DOUBLE
date_from_time(DOUBLE time
)
248 int dwy
= day_within_year(time
);
249 int ily
= in_leap_year(time
);
250 int mft
= month_from_time(time
);
255 if(mft
==0) return dwy
+1;
256 if(mft
==1) return dwy
-30;
257 if(mft
==2) return dwy
-58-ily
;
258 if(mft
==3) return dwy
-89-ily
;
259 if(mft
==4) return dwy
-119-ily
;
260 if(mft
==5) return dwy
-150-ily
;
261 if(mft
==6) return dwy
-180-ily
;
262 if(mft
==7) return dwy
-211-ily
;
263 if(mft
==8) return dwy
-242-ily
;
264 if(mft
==9) return dwy
-272-ily
;
265 if(mft
==10) return dwy
-303-ily
;
269 /* ECMA-262 3rd Edition 15.9.1.6 */
270 static inline DOUBLE
week_day(DOUBLE time
)
277 ret
= fmod(day(time
)+4, 7);
283 static inline DOUBLE
convert_time(int year
, SYSTEMTIME st
)
294 time
= time_from_year(year
);
295 time
+= (DOUBLE
)day_from_month(st
.wMonth
-1, in_leap_year(time
)) * MS_PER_DAY
;
298 set_week_day
= st
.wDayOfWeek
-week_day(time
);
301 time
+= set_week_day
* MS_PER_DAY
;
303 time
+= (DOUBLE
)(st
.wDay
-1) * 7 * MS_PER_DAY
;
304 if(month_from_time(time
) != st
.wMonth
-1)
305 time
-= 7 * MS_PER_DAY
;
308 time
+= st
.wDay
* MS_PER_DAY
;
310 time
+= st
.wHour
* MS_PER_HOUR
;
311 time
+= st
.wMinute
* MS_PER_MINUTE
;
316 /* ECMA-262 3rd Edition 15.9.1.9 */
317 static inline DOUBLE
daylight_saving_ta(DOUBLE time
, DateInstance
*date
)
319 int year
= year_from_time(time
);
320 DOUBLE standardTime
, daylightTime
;
325 standardTime
= convert_time(year
, date
->standardDate
);
326 daylightTime
= convert_time(year
, date
->daylightDate
);
328 if(isnan(standardTime
) || isnan(daylightTime
))
330 else if(standardTime
> daylightTime
) {
331 if(daylightTime
<= time
&& time
< standardTime
)
332 return date
->daylightBias
;
334 return date
->standardBias
;
337 if(standardTime
<= time
&& time
< daylightTime
)
338 return date
->standardBias
;
340 return date
->daylightBias
;
344 /* ECMA-262 3rd Edition 15.9.1.9 */
345 static inline DOUBLE
local_time(DOUBLE time
, DateInstance
*date
)
347 return time
- (daylight_saving_ta(time
, date
)+date
->bias
)*MS_PER_MINUTE
;
350 /* ECMA-262 3rd Edition 15.9.1.9 */
351 static inline DOUBLE
utc(DOUBLE time
, DateInstance
*date
)
353 time
+= date
->bias
* MS_PER_MINUTE
;
354 return time
+ daylight_saving_ta(time
, date
)*MS_PER_MINUTE
;
357 /* ECMA-262 3rd Edition 15.9.1.10 */
358 static inline DOUBLE
hour_from_time(DOUBLE time
)
365 ret
= fmod(floor(time
/MS_PER_HOUR
), 24);
371 /* ECMA-262 3rd Edition 15.9.1.10 */
372 static inline DOUBLE
min_from_time(DOUBLE time
)
379 ret
= fmod(floor(time
/MS_PER_MINUTE
), 60);
385 /* ECMA-262 3rd Edition 15.9.1.10 */
386 static inline DOUBLE
sec_from_time(DOUBLE time
)
393 ret
= fmod(floor(time
/1000), 60);
399 /* ECMA-262 3rd Edition 15.9.1.10 */
400 static inline DOUBLE
ms_from_time(DOUBLE time
)
407 ret
= fmod(time
, 1000);
408 if(ret
<0) ret
+= 1000;
413 /* ECMA-262 3rd Edition 15.9.1.11 */
414 static inline DOUBLE
make_time(DOUBLE hour
, DOUBLE min
, DOUBLE sec
, DOUBLE ms
)
416 return hour
*MS_PER_HOUR
+ min
*MS_PER_MINUTE
+ sec
*1000 + ms
;
419 /* ECMA-262 3rd Edition 15.9.1.12 */
420 static inline DOUBLE
make_day(DOUBLE year
, DOUBLE month
, DOUBLE day
)
424 year
+= floor(month
/12);
426 month
= fmod(month
, 12);
427 if(month
<0) month
+= 12;
429 time
= time_from_year(year
);
431 day
+= floor(time
/ MS_PER_DAY
);
432 day
+= day_from_month(month
, in_leap_year(time
));
437 /* ECMA-262 3rd Edition 15.9.1.13 */
438 static inline DOUBLE
make_date(DOUBLE day
, DOUBLE time
)
440 return day
*MS_PER_DAY
+ time
;
443 /* ECMA-262 3rd Edition 15.9.1.14 */
444 static inline DOUBLE
time_clip(DOUBLE time
)
446 if(8.64e15
< time
|| time
< -8.64e15
) {
453 static SYSTEMTIME
create_systemtime(DOUBLE time
)
457 st
.wYear
= year_from_time(time
);
458 st
.wMonth
= month_from_time(time
) + 1;
459 st
.wDayOfWeek
= week_day(time
);
460 st
.wDay
= date_from_time(time
);
461 st
.wHour
= hour_from_time(time
);
462 st
.wMinute
= min_from_time(time
);
463 st
.wSecond
= sec_from_time(time
);
464 st
.wMilliseconds
= ms_from_time(time
);
469 static inline HRESULT
date_to_string(DOUBLE time
, BOOL show_offset
, int offset
, jsval_t
*r
)
471 static const WCHAR formatW
[] = { '%','s',' ','%','s',' ','%','d',' ',
472 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
473 'U','T','C','%','c','%','0','2','d','%','0','2','d',' ','%','d','%','s',0 };
474 static const WCHAR formatUTCW
[] = { '%','s',' ','%','s',' ','%','d',' ',
475 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
476 'U','T','C',' ','%','d','%','s',0 };
477 static const WCHAR formatNoOffsetW
[] = { '%','s',' ','%','s',' ',
478 '%','d',' ','%','0','2','d',':','%','0','2','d',':',
479 '%','0','2','d',' ','%','d','%','s',0 };
480 static const WCHAR ADW
[] = { 0 };
481 static const WCHAR BCW
[] = { ' ','B','.','C','.',0 };
483 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
484 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
485 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
486 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
487 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
488 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
489 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
490 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
491 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
493 BOOL formatAD
= TRUE
;
494 WCHAR week
[64], month
[64];
496 int len
, size
, year
, day
;
502 *r
= jsval_string(jsstr_nan());
511 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
513 size
= GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(time
)], week
, sizeof(week
)/sizeof(*week
));
517 size
= GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(time
)], month
, sizeof(month
)/sizeof(*month
));
520 year
= year_from_time(time
);
528 year
= year_from_time(time
);
535 day
= date_from_time(time
);
540 day
= date_from_time(time
);
542 if(!show_offset
) len
-= 9;
543 else if(offset
== 0) len
-= 5;
544 else if(offset
< 0) {
549 date_str
= jsstr_alloc_buf(len
, &date_jsstr
);
551 return E_OUTOFMEMORY
;
554 sprintfW(date_str
, formatNoOffsetW
, week
, month
, day
,
555 (int)hour_from_time(time
), (int)min_from_time(time
),
556 (int)sec_from_time(time
), year
, formatAD
?ADW
:BCW
);
558 sprintfW(date_str
, formatW
, week
, month
, day
,
559 (int)hour_from_time(time
), (int)min_from_time(time
),
560 (int)sec_from_time(time
), sign
, offset
/60, offset
%60,
561 year
, formatAD
?ADW
:BCW
);
563 sprintfW(date_str
, formatUTCW
, week
, month
, day
,
564 (int)hour_from_time(time
), (int)min_from_time(time
),
565 (int)sec_from_time(time
), year
, formatAD
?ADW
:BCW
);
567 *r
= jsval_string(date_jsstr
);
572 /* ECMA-262 3rd Edition 15.9.1.2 */
573 static HRESULT
dateobj_to_string(DateInstance
*date
, jsval_t
*r
)
578 time
= local_time(date
->time
, date
);
579 offset
= date
->bias
+
580 daylight_saving_ta(time
, date
);
582 return date_to_string(time
, TRUE
, offset
, r
);
585 static HRESULT
Date_toString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
591 if(!(date
= date_this(jsthis
)))
592 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
594 return dateobj_to_string(date
, r
);
597 /* ECMA-262 3rd Edition 15.9.1.5 */
598 static HRESULT
Date_toLocaleString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
604 int date_len
, time_len
;
608 if(!(date
= date_this(jsthis
)))
609 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
611 if(isnan(date
->time
)) {
613 *r
= jsval_string(jsstr_nan());
617 st
= create_systemtime(local_time(date
->time
, date
));
619 if(st
.wYear
<1601 || st
.wYear
>9999)
620 return dateobj_to_string(date
, r
);
625 date_len
= GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, NULL
, 0);
626 time_len
= GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, NULL
, 0);
628 ptr
= jsstr_alloc_buf(date_len
+time_len
-1, &date_str
);
630 return E_OUTOFMEMORY
;
632 GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, ptr
, date_len
);
633 GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, ptr
+date_len
, time_len
);
634 ptr
[date_len
-1] = ' ';
636 *r
= jsval_string(date_str
);
641 static HRESULT
Date_valueOf(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
648 if(!(date
= date_this(jsthis
)))
649 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
652 *r
= jsval_number(date
->time
);
656 static inline HRESULT
create_utc_string(script_ctx_t
*ctx
, vdisp_t
*jsthis
, jsval_t
*r
)
658 static const WCHAR formatADW
[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ',
659 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
660 static const WCHAR formatBCW
[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ','B','.','C','.',' ',
661 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
663 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
664 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
665 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
666 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
667 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
668 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
669 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
670 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
671 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
673 BOOL formatAD
= TRUE
;
674 WCHAR week
[64], month
[64];
677 int len
, size
, year
, day
;
680 if(!(date
= date_this(jsthis
)))
681 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
683 if(isnan(date
->time
)) {
685 *r
= jsval_string(jsstr_nan());
694 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
696 size
= GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(date
->time
)], week
, sizeof(week
)/sizeof(*week
));
699 size
= GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(date
->time
)], month
, sizeof(month
)/sizeof(*month
));
702 year
= year_from_time(date
->time
);
710 year
= year_from_time(date
->time
);
717 day
= date_from_time(date
->time
);
722 day
= date_from_time(date
->time
);
724 ptr
= jsstr_alloc_buf(len
, &date_str
);
726 return E_OUTOFMEMORY
;
728 sprintfW(ptr
, formatAD
?formatADW
:formatBCW
, week
, day
, month
, year
,
729 (int)hour_from_time(date
->time
), (int)min_from_time(date
->time
),
730 (int)sec_from_time(date
->time
));
732 *r
= jsval_string(date_str
);
737 /* ECMA-262 3rd Edition 15.9.5.42 */
738 static HRESULT
Date_toUTCString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
742 return create_utc_string(ctx
, jsthis
, r
);
745 static HRESULT
Date_toGMTString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
749 return create_utc_string(ctx
, jsthis
, r
);
752 /* ECMA-262 3rd Edition 15.9.5.3 */
753 static HRESULT
dateobj_to_date_string(DateInstance
*date
, jsval_t
*r
)
755 static const WCHAR formatADW
[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',0 };
756 static const WCHAR formatBCW
[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',' ','B','.','C','.',0 };
758 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
759 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
760 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
761 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
762 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
763 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
764 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
765 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
766 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
768 BOOL formatAD
= TRUE
;
769 WCHAR week
[64], month
[64];
772 int len
, size
, year
, day
;
775 if(isnan(date
->time
)) {
777 *r
= jsval_string(jsstr_nan());
781 time
= local_time(date
->time
, date
);
788 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
790 size
= GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(time
)], week
, sizeof(week
)/sizeof(*week
));
794 size
= GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(time
)], month
, sizeof(month
)/sizeof(*month
));
798 year
= year_from_time(time
);
806 year
= year_from_time(time
);
813 day
= date_from_time(time
);
818 day
= date_from_time(time
);
820 ptr
= jsstr_alloc_buf(len
, &date_str
);
822 return E_OUTOFMEMORY
;
823 sprintfW(ptr
, formatAD
?formatADW
:formatBCW
, week
, month
, day
, year
);
825 *r
= jsval_string(date_str
);
830 static HRESULT
Date_toDateString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
835 if(!(date
= date_this(jsthis
)))
836 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
838 return dateobj_to_date_string(date
, r
);
841 /* ECMA-262 3rd Edition 15.9.5.4 */
842 static HRESULT
Date_toTimeString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
845 static const WCHAR formatW
[] = { '%','0','2','d',':','%','0','2','d',':','%','0','2','d',
846 ' ','U','T','C','%','c','%','0','2','d','%','0','2','d',0 };
847 static const WCHAR formatUTCW
[] = { '%','0','2','d',':','%','0','2','d',
848 ':','%','0','2','d',' ','U','T','C',0 };
857 if(!(date
= date_this(jsthis
)))
858 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
860 if(isnan(date
->time
)) {
862 *r
= jsval_string(jsstr_nan());
866 time
= local_time(date
->time
, date
);
871 ptr
= jsstr_alloc_buf(17, &date_str
);
873 return E_OUTOFMEMORY
;
875 offset
= date
->bias
+
876 daylight_saving_ta(time
, date
);
885 sprintfW(ptr
, formatW
, (int)hour_from_time(time
),
886 (int)min_from_time(time
), (int)sec_from_time(time
),
887 sign
, offset
/60, offset
%60);
889 sprintfW(ptr
, formatUTCW
, (int)hour_from_time(time
),
890 (int)min_from_time(time
), (int)sec_from_time(time
));
892 *r
= jsval_string(date_str
);
897 /* ECMA-262 3rd Edition 15.9.5.6 */
898 static HRESULT
Date_toLocaleDateString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
908 if(!(date
= date_this(jsthis
)))
909 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
911 if(isnan(date
->time
)) {
913 *r
= jsval_string(jsstr_nan());
917 st
= create_systemtime(local_time(date
->time
, date
));
919 if(st
.wYear
<1601 || st
.wYear
>9999)
920 return dateobj_to_date_string(date
, r
);
925 len
= GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, NULL
, 0);
926 ptr
= jsstr_alloc_buf(len
, &date_str
);
928 return E_OUTOFMEMORY
;
929 GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, ptr
, len
);
931 *r
= jsval_string(date_str
);
936 /* ECMA-262 3rd Edition 15.9.5.7 */
937 static HRESULT
Date_toLocaleTimeString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
947 if(!(date
= date_this(jsthis
)))
948 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
950 if(isnan(date
->time
)) {
952 *r
= jsval_string(jsstr_nan());
956 st
= create_systemtime(local_time(date
->time
, date
));
958 if(st
.wYear
<1601 || st
.wYear
>9999)
959 return Date_toTimeString(ctx
, jsthis
, flags
, argc
, argv
, r
);
964 len
= GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, NULL
, 0);
965 ptr
= jsstr_alloc_buf(len
, &date_str
);
967 return E_OUTOFMEMORY
;
968 GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, ptr
, len
);
970 *r
= jsval_string(date_str
);
975 /* ECMA-262 3rd Edition 15.9.5.9 */
976 static HRESULT
Date_getTime(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
983 if(!(date
= date_this(jsthis
)))
984 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
987 *r
= jsval_number(date
->time
);
991 /* ECMA-262 3rd Edition 15.9.5.10 */
992 static HRESULT
Date_getFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
999 if(!(date
= date_this(jsthis
)))
1000 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1003 DOUBLE time
= local_time(date
->time
, date
);
1005 *r
= jsval_number(year_from_time(time
));
1010 /* ECMA-262 3rd Edition 15.9.5.11 */
1011 static HRESULT
Date_getUTCFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1018 if(!(date
= date_this(jsthis
)))
1019 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1022 *r
= jsval_number(year_from_time(date
->time
));
1026 /* ECMA-262 3rd Edition 15.9.5.12 */
1027 static HRESULT
Date_getMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1033 if(!(date
= date_this(jsthis
)))
1034 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1037 *r
= jsval_number(month_from_time(local_time(date
->time
, date
)));
1041 /* ECMA-262 3rd Edition 15.9.5.13 */
1042 static HRESULT
Date_getUTCMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1049 if(!(date
= date_this(jsthis
)))
1050 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1053 *r
= jsval_number(month_from_time(date
->time
));
1057 /* ECMA-262 3rd Edition 15.9.5.14 */
1058 static HRESULT
Date_getDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1064 if(!(date
= date_this(jsthis
)))
1065 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1068 *r
= jsval_number(date_from_time(local_time(date
->time
, date
)));
1072 /* ECMA-262 3rd Edition 15.9.5.15 */
1073 static HRESULT
Date_getUTCDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1080 if(!(date
= date_this(jsthis
)))
1081 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1084 *r
= jsval_number(date_from_time(date
->time
));
1088 /* ECMA-262 3rd Edition 15.9.5.16 */
1089 static HRESULT
Date_getDay(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1096 if(!(date
= date_this(jsthis
)))
1097 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1100 *r
= jsval_number(week_day(local_time(date
->time
, date
)));
1104 /* ECMA-262 3rd Edition 15.9.5.17 */
1105 static HRESULT
Date_getUTCDay(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1112 if(!(date
= date_this(jsthis
)))
1113 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1116 *r
= jsval_number(week_day(date
->time
));
1120 /* ECMA-262 3rd Edition 15.9.5.18 */
1121 static HRESULT
Date_getHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1128 if(!(date
= date_this(jsthis
)))
1129 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1132 *r
= jsval_number(hour_from_time(local_time(date
->time
, date
)));
1136 /* ECMA-262 3rd Edition 15.9.5.19 */
1137 static HRESULT
Date_getUTCHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1144 if(!(date
= date_this(jsthis
)))
1145 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1148 *r
= jsval_number(hour_from_time(date
->time
));
1152 /* ECMA-262 3rd Edition 15.9.5.20 */
1153 static HRESULT
Date_getMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1160 if(!(date
= date_this(jsthis
)))
1161 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1164 *r
= jsval_number(min_from_time(local_time(date
->time
, date
)));
1168 /* ECMA-262 3rd Edition 15.9.5.21 */
1169 static HRESULT
Date_getUTCMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1176 if(!(date
= date_this(jsthis
)))
1177 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1180 *r
= jsval_number(min_from_time(date
->time
));
1184 /* ECMA-262 3rd Edition 15.9.5.22 */
1185 static HRESULT
Date_getSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1191 if(!(date
= date_this(jsthis
)))
1192 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1195 *r
= jsval_number(sec_from_time(local_time(date
->time
, date
)));
1199 /* ECMA-262 3rd Edition 15.9.5.23 */
1200 static HRESULT
Date_getUTCSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1207 if(!(date
= date_this(jsthis
)))
1208 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1211 *r
= jsval_number(sec_from_time(date
->time
));
1215 /* ECMA-262 3rd Edition 15.9.5.24 */
1216 static HRESULT
Date_getMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1223 if(!(date
= date_this(jsthis
)))
1224 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1227 *r
= jsval_number(ms_from_time(local_time(date
->time
, date
)));
1231 /* ECMA-262 3rd Edition 15.9.5.25 */
1232 static HRESULT
Date_getUTCMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1239 if(!(date
= date_this(jsthis
)))
1240 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1243 *r
= jsval_number(ms_from_time(date
->time
));
1247 /* ECMA-262 3rd Edition 15.9.5.26 */
1248 static HRESULT
Date_getTimezoneOffset(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1255 if(!(date
= date_this(jsthis
)))
1256 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1259 *r
= jsval_number(floor((date
->time
-local_time(date
->time
, date
))/MS_PER_MINUTE
));
1263 /* ECMA-262 3rd Edition 15.9.5.27 */
1264 static HRESULT
Date_setTime(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1273 if(!(date
= date_this(jsthis
)))
1274 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1277 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1279 hres
= to_number(ctx
, argv
[0], &n
);
1283 date
->time
= time_clip(n
);
1286 *r
= jsval_number(date
->time
);
1290 /* ECMA-262 3rd Edition 15.9.5.28 */
1291 static HRESULT
Date_setMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1300 if(!(date
= date_this(jsthis
)))
1301 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1304 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1306 hres
= to_number(ctx
, argv
[0], &n
);
1310 t
= local_time(date
->time
, date
);
1311 t
= make_date(day(t
), make_time(hour_from_time(t
), min_from_time(t
),
1312 sec_from_time(t
), n
));
1313 date
->time
= time_clip(utc(t
, date
));
1316 *r
= jsval_number(date
->time
);
1320 /* ECMA-262 3rd Edition 15.9.5.29 */
1321 static HRESULT
Date_setUTCMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1330 if(!(date
= date_this(jsthis
)))
1331 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1334 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1336 hres
= to_number(ctx
, argv
[0], &n
);
1341 t
= make_date(day(t
), make_time(hour_from_time(t
), min_from_time(t
),
1342 sec_from_time(t
), n
));
1343 date
->time
= time_clip(t
);
1346 *r
= jsval_number(date
->time
);
1350 /* ECMA-262 3rd Edition 15.9.5.30 */
1351 static HRESULT
Date_setSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1360 if(!(date
= date_this(jsthis
)))
1361 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1364 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1366 t
= local_time(date
->time
, date
);
1368 hres
= to_number(ctx
, argv
[0], &sec
);
1373 hres
= to_number(ctx
, argv
[1], &ms
);
1377 ms
= ms_from_time(t
);
1380 t
= make_date(day(t
), make_time(hour_from_time(t
),
1381 min_from_time(t
), sec
, ms
));
1382 date
->time
= time_clip(utc(t
, date
));
1385 *r
= jsval_number(date
->time
);
1389 /* ECMA-262 3rd Edition 15.9.5.31 */
1390 static HRESULT
Date_setUTCSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1399 if(!(date
= date_this(jsthis
)))
1400 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1403 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1407 hres
= to_number(ctx
, argv
[0], &sec
);
1412 hres
= to_number(ctx
, argv
[1], &ms
);
1416 ms
= ms_from_time(t
);
1419 t
= make_date(day(t
), make_time(hour_from_time(t
),
1420 min_from_time(t
), sec
, ms
));
1421 date
->time
= time_clip(t
);
1424 *r
= jsval_number(date
->time
);
1428 /* ECMA-262 3rd Edition 15.9.5.33 */
1429 static HRESULT
Date_setMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1433 double t
, min
, sec
, ms
;
1438 if(!(date
= date_this(jsthis
)))
1439 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1442 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1444 t
= local_time(date
->time
, date
);
1446 hres
= to_number(ctx
, argv
[0], &min
);
1451 hres
= to_number(ctx
, argv
[1], &sec
);
1455 sec
= sec_from_time(t
);
1459 hres
= to_number(ctx
, argv
[2], &ms
);
1463 ms
= ms_from_time(t
);
1466 t
= make_date(day(t
), make_time(hour_from_time(t
),
1468 date
->time
= time_clip(utc(t
, date
));
1471 *r
= jsval_number(date
->time
);
1475 /* ECMA-262 3rd Edition 15.9.5.34 */
1476 static HRESULT
Date_setUTCMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1480 double t
, min
, sec
, ms
;
1485 if(!(date
= date_this(jsthis
)))
1486 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1489 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1493 hres
= to_number(ctx
, argv
[0], &min
);
1498 hres
= to_number(ctx
, argv
[1], &sec
);
1502 sec
= sec_from_time(t
);
1506 hres
= to_number(ctx
, argv
[2], &ms
);
1510 ms
= ms_from_time(t
);
1513 t
= make_date(day(t
), make_time(hour_from_time(t
),
1515 date
->time
= time_clip(t
);
1518 *r
= jsval_number(date
->time
);
1522 /* ECMA-262 3rd Edition 15.9.5.35 */
1523 static HRESULT
Date_setHours(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
);
1538 t
= local_time(date
->time
, date
);
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(utc(t
, date
));
1572 *r
= jsval_number(date
->time
);
1576 /* ECMA-262 3rd Edition 15.9.5.36 */
1577 static HRESULT
Date_setUTCHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1581 double t
, hour
, min
, sec
, ms
;
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
);
1594 hres
= to_number(ctx
, argv
[0], &hour
);
1599 hres
= to_number(ctx
, argv
[1], &min
);
1603 min
= min_from_time(t
);
1607 hres
= to_number(ctx
, argv
[2], &sec
);
1611 sec
= sec_from_time(t
);
1615 hres
= to_number(ctx
, argv
[3], &ms
);
1619 ms
= ms_from_time(t
);
1622 t
= make_date(day(t
), make_time(hour
, min
, sec
, ms
));
1623 date
->time
= time_clip(t
);
1626 *r
= jsval_number(date
->time
);
1630 /* ECMA-262 3rd Edition 15.9.5.36 */
1631 static HRESULT
Date_setDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1640 if(!(date
= date_this(jsthis
)))
1641 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1644 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1646 hres
= to_number(ctx
, argv
[0], &n
);
1650 t
= local_time(date
->time
, date
);
1651 t
= make_date(make_day(year_from_time(t
), month_from_time(t
), n
), time_within_day(t
));
1652 date
->time
= time_clip(utc(t
, date
));
1655 *r
= jsval_number(date
->time
);
1659 /* ECMA-262 3rd Edition 15.9.5.37 */
1660 static HRESULT
Date_setUTCDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1669 if(!(date
= date_this(jsthis
)))
1670 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1673 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1675 hres
= to_number(ctx
, argv
[0], &n
);
1680 t
= make_date(make_day(year_from_time(t
), month_from_time(t
), n
), time_within_day(t
));
1681 date
->time
= time_clip(t
);
1684 *r
= jsval_number(date
->time
);
1688 /* ECMA-262 3rd Edition 15.9.5.38 */
1689 static HRESULT
Date_setMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1693 DOUBLE t
, month
, ddate
;
1698 if(!(date
= date_this(jsthis
)))
1699 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1702 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1704 t
= local_time(date
->time
, date
);
1706 hres
= to_number(ctx
, argv
[0], &month
);
1711 hres
= to_number(ctx
, argv
[1], &ddate
);
1715 ddate
= date_from_time(t
);
1718 t
= make_date(make_day(year_from_time(t
), month
, ddate
),
1719 time_within_day(t
));
1720 date
->time
= time_clip(utc(t
, date
));
1723 *r
= jsval_number(date
->time
);
1727 /* ECMA-262 3rd Edition 15.9.5.39 */
1728 static HRESULT
Date_setUTCMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1732 double t
, month
, ddate
;
1737 if(!(date
= date_this(jsthis
)))
1738 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1741 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1745 hres
= to_number(ctx
, argv
[0], &month
);
1750 hres
= to_number(ctx
, argv
[1], &ddate
);
1754 ddate
= date_from_time(t
);
1757 t
= make_date(make_day(year_from_time(t
), month
, ddate
),
1758 time_within_day(t
));
1759 date
->time
= time_clip(t
);
1762 *r
= jsval_number(date
->time
);
1766 /* ECMA-262 3rd Edition 15.9.5.40 */
1767 static HRESULT
Date_setFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1771 double t
, year
, month
, ddate
;
1776 if(!(date
= date_this(jsthis
)))
1777 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1780 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1782 t
= local_time(date
->time
, date
);
1784 hres
= to_number(ctx
, argv
[0], &year
);
1789 hres
= to_number(ctx
, argv
[1], &month
);
1793 month
= month_from_time(t
);
1797 hres
= to_number(ctx
, argv
[2], &ddate
);
1801 ddate
= date_from_time(t
);
1804 t
= make_date(make_day(year
, month
, ddate
), time_within_day(t
));
1805 date
->time
= time_clip(utc(t
, date
));
1808 *r
= jsval_number(date
->time
);
1812 /* ECMA-262 3rd Edition 15.9.5.41 */
1813 static HRESULT
Date_setUTCFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1817 double t
, year
, month
, ddate
;
1822 if(!(date
= date_this(jsthis
)))
1823 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1826 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1830 hres
= to_number(ctx
, argv
[0], &year
);
1835 hres
= to_number(ctx
, argv
[1], &month
);
1839 month
= month_from_time(t
);
1843 hres
= to_number(ctx
, argv
[2], &ddate
);
1847 ddate
= date_from_time(t
);
1850 t
= make_date(make_day(year
, month
, ddate
), time_within_day(t
));
1851 date
->time
= time_clip(t
);
1854 *r
= jsval_number(date
->time
);
1858 /* ECMA-262 3rd Edition B2.4 */
1859 static HRESULT
Date_getYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1867 if(!(date
= date_this(jsthis
)))
1868 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1870 t
= local_time(date
->time
, date
);
1873 *r
= jsval_number(NAN
);
1877 year
= year_from_time(t
);
1879 *r
= jsval_number((1900<=year
&& year
<2000)?year
-1900:year
);
1883 /* ECMA-262 3rd Edition B2.5 */
1884 static HRESULT
Date_setYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1893 if(!(date
= date_this(jsthis
)))
1894 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1897 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1899 t
= local_time(date
->time
, date
);
1901 hres
= to_number(ctx
, argv
[0], &year
);
1908 *r
= jsval_number(NAN
);
1912 year
= year
>= 0.0 ? floor(year
) : -floor(-year
);
1913 if(-1.0 < year
&& year
< 100.0)
1916 date
->time
= time_clip(utc(make_date(make_day(year
, month_from_time(t
), date_from_time(t
)), time_within_day(t
)), date
));
1919 *r
= jsval_number(date
->time
);
1923 static HRESULT
Date_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1930 return throw_type_error(ctx
, JS_E_FUNCTION_EXPECTED
, NULL
);
1932 FIXME("unimplemented flags %x\n", flags
);
1939 static const builtin_prop_t Date_props
[] = {
1940 {getDateW
, Date_getDate
, PROPF_METHOD
},
1941 {getDayW
, Date_getDay
, PROPF_METHOD
},
1942 {getFullYearW
, Date_getFullYear
, PROPF_METHOD
},
1943 {getHoursW
, Date_getHours
, PROPF_METHOD
},
1944 {getMillisecondsW
, Date_getMilliseconds
, PROPF_METHOD
},
1945 {getMinutesW
, Date_getMinutes
, PROPF_METHOD
},
1946 {getMonthW
, Date_getMonth
, PROPF_METHOD
},
1947 {getSecondsW
, Date_getSeconds
, PROPF_METHOD
},
1948 {getTimeW
, Date_getTime
, PROPF_METHOD
},
1949 {getTimezoneOffsetW
, Date_getTimezoneOffset
, PROPF_METHOD
},
1950 {getUTCDateW
, Date_getUTCDate
, PROPF_METHOD
},
1951 {getUTCDayW
, Date_getUTCDay
, PROPF_METHOD
},
1952 {getUTCFullYearW
, Date_getUTCFullYear
, PROPF_METHOD
},
1953 {getUTCHoursW
, Date_getUTCHours
, PROPF_METHOD
},
1954 {getUTCMillisecondsW
, Date_getUTCMilliseconds
, PROPF_METHOD
},
1955 {getUTCMinutesW
, Date_getUTCMinutes
, PROPF_METHOD
},
1956 {getUTCMonthW
, Date_getUTCMonth
, PROPF_METHOD
},
1957 {getUTCSecondsW
, Date_getUTCSeconds
, PROPF_METHOD
},
1958 {getYearW
, Date_getYear
, PROPF_METHOD
},
1959 {setDateW
, Date_setDate
, PROPF_METHOD
|1},
1960 {setFullYearW
, Date_setFullYear
, PROPF_METHOD
|3},
1961 {setHoursW
, Date_setHours
, PROPF_METHOD
|4},
1962 {setMillisecondsW
, Date_setMilliseconds
, PROPF_METHOD
|1},
1963 {setMinutesW
, Date_setMinutes
, PROPF_METHOD
|3},
1964 {setMonthW
, Date_setMonth
, PROPF_METHOD
|2},
1965 {setSecondsW
, Date_setSeconds
, PROPF_METHOD
|2},
1966 {setTimeW
, Date_setTime
, PROPF_METHOD
|1},
1967 {setUTCDateW
, Date_setUTCDate
, PROPF_METHOD
|1},
1968 {setUTCFullYearW
, Date_setUTCFullYear
, PROPF_METHOD
|3},
1969 {setUTCHoursW
, Date_setUTCHours
, PROPF_METHOD
|4},
1970 {setUTCMillisecondsW
, Date_setUTCMilliseconds
, PROPF_METHOD
|1},
1971 {setUTCMinutesW
, Date_setUTCMinutes
, PROPF_METHOD
|3},
1972 {setUTCMonthW
, Date_setUTCMonth
, PROPF_METHOD
|2},
1973 {setUTCSecondsW
, Date_setUTCSeconds
, PROPF_METHOD
|2},
1974 {setYearW
, Date_setYear
, PROPF_METHOD
|1},
1975 {toDateStringW
, Date_toDateString
, PROPF_METHOD
},
1976 {toGMTStringW
, Date_toGMTString
, PROPF_METHOD
},
1977 {toLocaleDateStringW
, Date_toLocaleDateString
, PROPF_METHOD
},
1978 {toLocaleStringW
, Date_toLocaleString
, PROPF_METHOD
},
1979 {toLocaleTimeStringW
, Date_toLocaleTimeString
, PROPF_METHOD
},
1980 {toStringW
, Date_toString
, PROPF_METHOD
},
1981 {toTimeStringW
, Date_toTimeString
, PROPF_METHOD
},
1982 {toUTCStringW
, Date_toUTCString
, PROPF_METHOD
},
1983 {valueOfW
, Date_valueOf
, PROPF_METHOD
},
1986 static const builtin_info_t Date_info
= {
1988 {NULL
, Date_value
, 0},
1989 sizeof(Date_props
)/sizeof(*Date_props
),
1995 static const builtin_info_t DateInst_info
= {
1997 {NULL
, Date_value
, 0},
2003 static HRESULT
create_date(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
, DOUBLE time
, jsdisp_t
**ret
)
2007 TIME_ZONE_INFORMATION tzi
;
2009 GetTimeZoneInformation(&tzi
);
2011 date
= heap_alloc_zero(sizeof(DateInstance
));
2013 return E_OUTOFMEMORY
;
2015 if(object_prototype
)
2016 hres
= init_dispex(&date
->dispex
, ctx
, &Date_info
, object_prototype
);
2018 hres
= init_dispex_from_constr(&date
->dispex
, ctx
, &DateInst_info
, ctx
->date_constr
);
2025 date
->bias
= tzi
.Bias
;
2026 date
->standardDate
= tzi
.StandardDate
;
2027 date
->standardBias
= tzi
.StandardBias
;
2028 date
->daylightDate
= tzi
.DaylightDate
;
2029 date
->daylightBias
= tzi
.DaylightBias
;
2031 *ret
= &date
->dispex
;
2035 static inline HRESULT
date_parse(jsstr_t
*input_str
, double *ret
) {
2036 static const DWORD string_ids
[] = { LOCALE_SMONTHNAME12
, LOCALE_SMONTHNAME11
,
2037 LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME8
,
2038 LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME5
,
2039 LOCALE_SMONTHNAME4
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME2
,
2040 LOCALE_SMONTHNAME1
, LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
,
2041 LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
, LOCALE_SDAYNAME4
,
2042 LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
};
2043 WCHAR
*strings
[sizeof(string_ids
)/sizeof(DWORD
)];
2045 int input_len
, parse_len
= 0, nest_level
= 0, i
, size
;
2046 int year
= 0, month
= 0, day
= 0, hour
= 0, min
= 0, sec
= 0;
2047 int ms
= 0, offset
= 0, hour_adjust
= 0;
2048 BOOL set_year
= FALSE
, set_month
= FALSE
, set_day
= FALSE
, set_hour
= FALSE
;
2049 BOOL set_offset
= FALSE
, set_era
= FALSE
, ad
= TRUE
, set_am
= FALSE
, am
= TRUE
;
2050 BOOL set_hour_adjust
= TRUE
;
2051 TIME_ZONE_INFORMATION tzi
;
2056 input_len
= jsstr_length(input_str
);
2057 input
= jsstr_flatten(input_str
);
2059 return E_OUTOFMEMORY
;
2061 for(i
=0; i
<input_len
; i
++) {
2062 if(input
[i
] == '(') nest_level
++;
2063 else if(input
[i
] == ')') {
2070 else if(!nest_level
) parse_len
++;
2073 parse
= heap_alloc((parse_len
+1)*sizeof(WCHAR
));
2075 return E_OUTOFMEMORY
;
2078 for(i
=0; i
<input_len
; i
++) {
2079 if(input
[i
] == '(') nest_level
++;
2080 else if(input
[i
] == ')') nest_level
--;
2081 else if(!nest_level
) parse
[parse_len
++] = toupperW(input
[i
]);
2083 parse
[parse_len
] = 0;
2085 GetTimeZoneInformation(&tzi
);
2087 di
.standardDate
= tzi
.StandardDate
;
2088 di
.standardBias
= tzi
.StandardBias
;
2089 di
.daylightDate
= tzi
.DaylightDate
;
2090 di
.daylightBias
= tzi
.DaylightBias
;
2092 /* FIXME: Cache strings */
2093 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2094 for(i
=0; i
<sizeof(string_ids
)/sizeof(DWORD
); i
++) {
2095 size
= GetLocaleInfoW(lcid_en
, string_ids
[i
], NULL
, 0);
2096 strings
[i
] = heap_alloc((size
+1)*sizeof(WCHAR
));
2100 heap_free(strings
[i
]);
2102 return E_OUTOFMEMORY
;
2104 GetLocaleInfoW(lcid_en
, string_ids
[i
], strings
[i
], size
);
2107 for(i
=0; i
<parse_len
;) {
2108 while(isspaceW(parse
[i
])) i
++;
2109 if(parse
[i
] == ',') {
2110 while(parse
[i
] == ',') i
++;
2114 if(parse
[i
]>='0' && parse
[i
]<='9') {
2115 int tmp
= atoiW(&parse
[i
]);
2116 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2117 while(isspaceW(parse
[i
])) i
++;
2119 if(parse
[i
] == ':') {
2126 while(parse
[i
] == ':') i
++;
2127 while(isspaceW(parse
[i
])) i
++;
2128 if(parse
[i
]>='0' && parse
[i
]<='9') {
2129 min
= atoiW(&parse
[i
]);
2130 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2133 while(isspaceW(parse
[i
])) i
++;
2134 while(parse
[i
] == ':') i
++;
2135 while(isspaceW(parse
[i
])) i
++;
2136 if(parse
[i
]>='0' && parse
[i
]<='9') {
2137 sec
= atoiW(&parse
[i
]);
2138 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2141 else if(parse
[i
]=='-' || parse
[i
]=='/') {
2143 if(set_day
|| set_month
|| set_year
) break;
2150 while(isspaceW(parse
[i
])) i
++;
2151 while(parse
[i
]=='-' || parse
[i
]=='/') i
++;
2152 while(isspaceW(parse
[i
])) i
++;
2153 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2154 day
= atoiW(&parse
[i
]);
2155 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2157 while(parse
[i
]=='-' || parse
[i
]=='/') i
++;
2158 while(isspaceW(parse
[i
])) i
++;
2159 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2160 year
= atoiW(&parse
[i
]);
2161 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2163 else if(tmp
<0) break;
2178 if(parse
[i
]<'A' || parse
[i
]>'Z') break;
2179 else if(parse
[i
]=='B' && (parse
[i
+1]=='C' ||
2180 (parse
[i
+1]=='.' && parse
[i
+2]=='C'))) {
2187 if(parse
[i
] == '.') i
++;
2189 if(parse
[i
] == '.') i
++;
2191 else if(parse
[i
]=='A' && (parse
[i
+1]=='D' ||
2192 (parse
[i
+1]=='.' && parse
[i
+2]=='D'))) {
2198 if(parse
[i
] == '.') i
++;
2200 if(parse
[i
] == '.') i
++;
2202 else if(parse
[i
+1]<'A' || parse
[i
+1]>'Z') {
2204 if(set_offset
) break;
2207 if(parse
[i
] <= 'I') hour_adjust
= parse
[i
]-'A'+2;
2208 else if(parse
[i
] == 'J') break;
2209 else if(parse
[i
] <= 'M') hour_adjust
= parse
[i
]-'K'+11;
2210 else if(parse
[i
] <= 'Y') hour_adjust
= parse
[i
]-'N';
2211 else hour_adjust
= 1;
2214 if(parse
[i
] == '.') i
++;
2216 else if(parse
[i
]=='A' && parse
[i
+1]=='M') {
2223 else if(parse
[i
]=='P' && parse
[i
+1]=='M') {
2230 else if((parse
[i
]=='U' && parse
[i
+1]=='T' && parse
[i
+2]=='C')
2231 || (parse
[i
]=='G' && parse
[i
+1]=='M' && parse
[i
+2]=='T')) {
2233 BOOL positive
= TRUE
;
2235 if(set_offset
) break;
2237 set_hour_adjust
= FALSE
;
2240 while(isspaceW(parse
[i
])) i
++;
2241 if(parse
[i
] == '-') positive
= FALSE
;
2242 else if(parse
[i
] != '+') continue;
2245 while(isspaceW(parse
[i
])) i
++;
2246 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2247 offset
= atoiW(&parse
[i
]);
2248 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2250 if(offset
<24) offset
*= 60;
2251 else offset
= (offset
/100)*60 + offset
%100;
2253 if(positive
) offset
= -offset
;
2256 /* Month or garbage */
2259 for(size
=i
; parse
[size
]>='A' && parse
[size
]<='Z'; size
++);
2262 for(j
=0; j
<sizeof(string_ids
)/sizeof(DWORD
); j
++)
2263 if(!strncmpiW(&parse
[i
], strings
[j
], size
)) break;
2266 if(set_month
) break;
2270 else if(j
== sizeof(string_ids
)/sizeof(DWORD
)) break;
2277 if(i
== parse_len
&& set_year
&& set_month
&& set_day
&& (!set_am
|| hour
<13)) {
2279 if(hour
== 12) hour
= 0;
2283 if(!ad
) year
= -year
+1;
2284 else if(year
<100) year
+= 1900;
2286 *ret
= time_clip(make_date(make_day(year
, month
, day
),
2287 make_time(hour
+hour_adjust
, min
, sec
, ms
)) + offset
*MS_PER_MINUTE
);
2290 *ret
= utc(*ret
, &di
);
2295 for(i
=0; i
<sizeof(string_ids
)/sizeof(DWORD
); i
++)
2296 heap_free(strings
[i
]);
2302 static HRESULT
DateConstr_parse(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2313 *r
= jsval_number(NAN
);
2317 hres
= to_string(ctx
, argv
[0], &parse_str
);
2321 hres
= date_parse(parse_str
, &n
);
2322 jsstr_release(parse_str
);
2326 *r
= jsval_number(n
);
2330 static HRESULT
date_utc(script_ctx_t
*ctx
, unsigned argc
, jsval_t
*argv
, double *ret
)
2332 double year
, month
, vdate
, hours
, minutes
, seconds
, ms
;
2338 hres
= to_number(ctx
, argv
[0], &year
);
2341 if(0 <= year
&& year
<= 99)
2348 hres
= to_number(ctx
, argv
[1], &month
);
2356 hres
= to_number(ctx
, argv
[2], &vdate
);
2364 hres
= to_number(ctx
, argv
[3], &hours
);
2372 hres
= to_number(ctx
, argv
[4], &minutes
);
2380 hres
= to_number(ctx
, argv
[5], &seconds
);
2388 hres
= to_number(ctx
, argv
[6], &ms
);
2395 *ret
= time_clip(make_date(make_day(year
, month
, vdate
),
2396 make_time(hours
, minutes
,seconds
, ms
)));
2400 static HRESULT
DateConstr_UTC(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2408 hres
= date_utc(ctx
, argc
, argv
, &n
);
2409 if(SUCCEEDED(hres
) && r
)
2410 *r
= jsval_number(n
);
2414 static HRESULT
DateConstr_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2423 case DISPATCH_CONSTRUCT
:
2425 /* ECMA-262 3rd Edition 15.9.3.3 */
2430 GetSystemTimeAsFileTime(&time
);
2431 lltime
= ((LONGLONG
)time
.dwHighDateTime
<<32)
2432 + time
.dwLowDateTime
;
2434 hres
= create_date(ctx
, NULL
, lltime
/10000-TIME_EPOCH
, &date
);
2440 /* ECMA-262 3rd Edition 15.9.3.2 */
2445 hres
= to_primitive(ctx
, argv
[0], &prim
, NO_HINT
);
2450 hres
= date_parse(get_string(prim
), &n
);
2452 hres
= to_number(ctx
, prim
, &n
);
2454 jsval_release(prim
);
2458 hres
= create_date(ctx
, NULL
, time_clip(n
), &date
);
2464 /* ECMA-262 3rd Edition 15.9.3.1 */
2469 hres
= date_utc(ctx
, argc
, argv
, &ret_date
);
2473 hres
= create_date(ctx
, NULL
, ret_date
, &date
);
2477 di
= (DateInstance
*)date
;
2478 di
->time
= utc(di
->time
, di
);
2482 *r
= jsval_obj(date
);
2486 FILETIME system_time
, local_time
;
2489 GetSystemTimeAsFileTime(&system_time
);
2490 FileTimeToLocalFileTime(&system_time
, &local_time
);
2491 lltime
= ((LONGLONG
)local_time
.dwHighDateTime
<<32)
2492 + local_time
.dwLowDateTime
;
2494 return date_to_string(lltime
/10000-TIME_EPOCH
, FALSE
, 0, r
);
2498 FIXME("unimplemented flags %x\n", flags
);
2505 static const builtin_prop_t DateConstr_props
[] = {
2506 {UTCW
, DateConstr_UTC
, PROPF_METHOD
},
2507 {parseW
, DateConstr_parse
, PROPF_METHOD
}
2510 static const builtin_info_t DateConstr_info
= {
2512 {NULL
, Function_value
, 0},
2513 sizeof(DateConstr_props
)/sizeof(*DateConstr_props
),
2519 HRESULT
create_date_constr(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
, jsdisp_t
**ret
)
2524 static const WCHAR DateW
[] = {'D','a','t','e',0};
2526 hres
= create_date(ctx
, object_prototype
, 0.0, &date
);
2530 hres
= create_builtin_constructor(ctx
, DateConstr_value
, DateW
, &DateConstr_info
,
2531 PROPF_CONSTR
|7, date
, ret
);
2533 jsdisp_release(date
);