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];
498 int len
, size
, year
, day
;
504 *r
= jsval_string(jsstr_nan());
513 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
515 size
= GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(time
)], week
, sizeof(week
)/sizeof(*week
));
519 size
= GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(time
)], month
, sizeof(month
)/sizeof(*month
));
522 year
= year_from_time(time
);
530 year
= year_from_time(time
);
537 day
= date_from_time(time
);
542 day
= date_from_time(time
);
544 if(!show_offset
) len
-= 9;
545 else if(offset
== 0) len
-= 5;
546 else if(offset
< 0) {
551 date_str
= jsstr_alloc_buf(len
, &date_jsstr
);
553 return E_OUTOFMEMORY
;
556 sprintfW(date_str
, formatNoOffsetW
, week
, month
, day
,
557 (int)hour_from_time(time
), (int)min_from_time(time
),
558 (int)sec_from_time(time
), year
, formatAD
?ADW
:BCW
);
560 sprintfW(date_str
, formatW
, week
, month
, day
,
561 (int)hour_from_time(time
), (int)min_from_time(time
),
562 (int)sec_from_time(time
), sign
, offset
/60, offset
%60,
563 year
, formatAD
?ADW
:BCW
);
565 sprintfW(date_str
, formatUTCW
, week
, month
, day
,
566 (int)hour_from_time(time
), (int)min_from_time(time
),
567 (int)sec_from_time(time
), year
, formatAD
?ADW
:BCW
);
569 *r
= jsval_string(date_jsstr
);
574 /* ECMA-262 3rd Edition 15.9.1.2 */
575 static HRESULT
dateobj_to_string(DateInstance
*date
, jsval_t
*r
)
580 time
= local_time(date
->time
, date
);
581 offset
= date
->bias
+
582 daylight_saving_ta(time
, date
);
584 return date_to_string(time
, TRUE
, offset
, r
);
587 static HRESULT
Date_toString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
593 if(!(date
= date_this(jsthis
)))
594 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
596 return dateobj_to_string(date
, r
);
599 /* ECMA-262 3rd Edition 15.9.1.5 */
600 static HRESULT
Date_toLocaleString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
606 int date_len
, time_len
;
610 if(!(date
= date_this(jsthis
)))
611 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
613 if(isnan(date
->time
)) {
615 *r
= jsval_string(jsstr_nan());
619 st
= create_systemtime(local_time(date
->time
, date
));
621 if(st
.wYear
<1601 || st
.wYear
>9999)
622 return dateobj_to_string(date
, r
);
627 date_len
= GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, NULL
, 0);
628 time_len
= GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, NULL
, 0);
630 ptr
= jsstr_alloc_buf(date_len
+time_len
-1, &date_str
);
632 return E_OUTOFMEMORY
;
634 GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, ptr
, date_len
);
635 GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, ptr
+date_len
, time_len
);
636 ptr
[date_len
-1] = ' ';
638 *r
= jsval_string(date_str
);
643 static HRESULT
Date_valueOf(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
650 if(!(date
= date_this(jsthis
)))
651 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
654 *r
= jsval_number(date
->time
);
658 static inline HRESULT
create_utc_string(script_ctx_t
*ctx
, vdisp_t
*jsthis
, jsval_t
*r
)
660 static const WCHAR formatADW
[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ',
661 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
662 static const WCHAR formatBCW
[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ','B','.','C','.',' ',
663 '%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
665 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
666 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
667 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
668 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
669 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
670 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
671 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
672 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
673 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
675 BOOL formatAD
= TRUE
;
676 WCHAR week
[64], month
[64];
679 int len
, size
, year
, day
;
682 if(!(date
= date_this(jsthis
)))
683 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
685 if(isnan(date
->time
)) {
687 *r
= jsval_string(jsstr_nan());
696 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
698 size
= GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(date
->time
)], week
, sizeof(week
)/sizeof(*week
));
701 size
= GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(date
->time
)], month
, sizeof(month
)/sizeof(*month
));
704 year
= year_from_time(date
->time
);
712 year
= year_from_time(date
->time
);
719 day
= date_from_time(date
->time
);
724 day
= date_from_time(date
->time
);
726 ptr
= jsstr_alloc_buf(len
, &date_str
);
728 return E_OUTOFMEMORY
;
730 sprintfW(ptr
, formatAD
?formatADW
:formatBCW
, week
, day
, month
, year
,
731 (int)hour_from_time(date
->time
), (int)min_from_time(date
->time
),
732 (int)sec_from_time(date
->time
));
734 *r
= jsval_string(date_str
);
739 /* ECMA-262 3rd Edition 15.9.5.42 */
740 static HRESULT
Date_toUTCString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
744 return create_utc_string(ctx
, jsthis
, r
);
747 static HRESULT
Date_toGMTString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
751 return create_utc_string(ctx
, jsthis
, r
);
754 /* ECMA-262 3rd Edition 15.9.5.3 */
755 static HRESULT
dateobj_to_date_string(DateInstance
*date
, jsval_t
*r
)
757 static const WCHAR formatADW
[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',0 };
758 static const WCHAR formatBCW
[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',' ','B','.','C','.',0 };
760 static const DWORD week_ids
[] = { LOCALE_SABBREVDAYNAME7
, LOCALE_SABBREVDAYNAME1
,
761 LOCALE_SABBREVDAYNAME2
, LOCALE_SABBREVDAYNAME3
, LOCALE_SABBREVDAYNAME4
,
762 LOCALE_SABBREVDAYNAME5
, LOCALE_SABBREVDAYNAME6
};
763 static const DWORD month_ids
[] = { LOCALE_SABBREVMONTHNAME1
, LOCALE_SABBREVMONTHNAME2
,
764 LOCALE_SABBREVMONTHNAME3
, LOCALE_SABBREVMONTHNAME4
,
765 LOCALE_SABBREVMONTHNAME5
, LOCALE_SABBREVMONTHNAME6
,
766 LOCALE_SABBREVMONTHNAME7
, LOCALE_SABBREVMONTHNAME8
,
767 LOCALE_SABBREVMONTHNAME9
, LOCALE_SABBREVMONTHNAME10
,
768 LOCALE_SABBREVMONTHNAME11
, LOCALE_SABBREVMONTHNAME12
};
770 BOOL formatAD
= TRUE
;
771 WCHAR week
[64], month
[64];
774 int len
, size
, year
, day
;
777 if(isnan(date
->time
)) {
779 *r
= jsval_string(jsstr_nan());
783 time
= local_time(date
->time
, date
);
790 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
792 size
= GetLocaleInfoW(lcid_en
, week_ids
[(int)week_day(time
)], week
, sizeof(week
)/sizeof(*week
));
796 size
= GetLocaleInfoW(lcid_en
, month_ids
[(int)month_from_time(time
)], month
, sizeof(month
)/sizeof(*month
));
800 year
= year_from_time(time
);
808 year
= year_from_time(time
);
815 day
= date_from_time(time
);
820 day
= date_from_time(time
);
822 ptr
= jsstr_alloc_buf(len
, &date_str
);
824 return E_OUTOFMEMORY
;
825 sprintfW(ptr
, formatAD
?formatADW
:formatBCW
, week
, month
, day
, year
);
827 *r
= jsval_string(date_str
);
832 static HRESULT
Date_toDateString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
837 if(!(date
= date_this(jsthis
)))
838 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
840 return dateobj_to_date_string(date
, r
);
843 /* ECMA-262 3rd Edition 15.9.5.4 */
844 static HRESULT
Date_toTimeString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
847 static const WCHAR formatW
[] = { '%','0','2','d',':','%','0','2','d',':','%','0','2','d',
848 ' ','U','T','C','%','c','%','0','2','d','%','0','2','d',0 };
849 static const WCHAR formatUTCW
[] = { '%','0','2','d',':','%','0','2','d',
850 ':','%','0','2','d',' ','U','T','C',0 };
859 if(!(date
= date_this(jsthis
)))
860 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
862 if(isnan(date
->time
)) {
864 *r
= jsval_string(jsstr_nan());
868 time
= local_time(date
->time
, date
);
873 ptr
= jsstr_alloc_buf(17, &date_str
);
875 return E_OUTOFMEMORY
;
877 offset
= date
->bias
+
878 daylight_saving_ta(time
, date
);
887 sprintfW(ptr
, formatW
, (int)hour_from_time(time
),
888 (int)min_from_time(time
), (int)sec_from_time(time
),
889 sign
, offset
/60, offset
%60);
891 sprintfW(ptr
, formatUTCW
, (int)hour_from_time(time
),
892 (int)min_from_time(time
), (int)sec_from_time(time
));
894 *r
= jsval_string(date_str
);
899 /* ECMA-262 3rd Edition 15.9.5.6 */
900 static HRESULT
Date_toLocaleDateString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
910 if(!(date
= date_this(jsthis
)))
911 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
913 if(isnan(date
->time
)) {
915 *r
= jsval_string(jsstr_nan());
919 st
= create_systemtime(local_time(date
->time
, date
));
921 if(st
.wYear
<1601 || st
.wYear
>9999)
922 return dateobj_to_date_string(date
, r
);
927 len
= GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, NULL
, 0);
928 ptr
= jsstr_alloc_buf(len
, &date_str
);
930 return E_OUTOFMEMORY
;
931 GetDateFormatW(ctx
->lcid
, DATE_LONGDATE
, &st
, NULL
, ptr
, len
);
933 *r
= jsval_string(date_str
);
938 /* ECMA-262 3rd Edition 15.9.5.7 */
939 static HRESULT
Date_toLocaleTimeString(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
949 if(!(date
= date_this(jsthis
)))
950 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
952 if(isnan(date
->time
)) {
954 *r
= jsval_string(jsstr_nan());
958 st
= create_systemtime(local_time(date
->time
, date
));
960 if(st
.wYear
<1601 || st
.wYear
>9999)
961 return Date_toTimeString(ctx
, jsthis
, flags
, argc
, argv
, r
);
966 len
= GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, NULL
, 0);
967 ptr
= jsstr_alloc_buf(len
, &date_str
);
969 return E_OUTOFMEMORY
;
970 GetTimeFormatW(ctx
->lcid
, 0, &st
, NULL
, ptr
, len
);
972 *r
= jsval_string(date_str
);
977 /* ECMA-262 3rd Edition 15.9.5.9 */
978 static HRESULT
Date_getTime(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
985 if(!(date
= date_this(jsthis
)))
986 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
989 *r
= jsval_number(date
->time
);
993 /* ECMA-262 3rd Edition 15.9.5.10 */
994 static HRESULT
Date_getFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1001 if(!(date
= date_this(jsthis
)))
1002 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1005 DOUBLE time
= local_time(date
->time
, date
);
1007 *r
= jsval_number(year_from_time(time
));
1012 /* ECMA-262 3rd Edition 15.9.5.11 */
1013 static HRESULT
Date_getUTCFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1020 if(!(date
= date_this(jsthis
)))
1021 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1024 *r
= jsval_number(year_from_time(date
->time
));
1028 /* ECMA-262 3rd Edition 15.9.5.12 */
1029 static HRESULT
Date_getMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1035 if(!(date
= date_this(jsthis
)))
1036 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1039 *r
= jsval_number(month_from_time(local_time(date
->time
, date
)));
1043 /* ECMA-262 3rd Edition 15.9.5.13 */
1044 static HRESULT
Date_getUTCMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1051 if(!(date
= date_this(jsthis
)))
1052 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1055 *r
= jsval_number(month_from_time(date
->time
));
1059 /* ECMA-262 3rd Edition 15.9.5.14 */
1060 static HRESULT
Date_getDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1066 if(!(date
= date_this(jsthis
)))
1067 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1070 *r
= jsval_number(date_from_time(local_time(date
->time
, date
)));
1074 /* ECMA-262 3rd Edition 15.9.5.15 */
1075 static HRESULT
Date_getUTCDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1082 if(!(date
= date_this(jsthis
)))
1083 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1086 *r
= jsval_number(date_from_time(date
->time
));
1090 /* ECMA-262 3rd Edition 15.9.5.16 */
1091 static HRESULT
Date_getDay(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1098 if(!(date
= date_this(jsthis
)))
1099 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1102 *r
= jsval_number(week_day(local_time(date
->time
, date
)));
1106 /* ECMA-262 3rd Edition 15.9.5.17 */
1107 static HRESULT
Date_getUTCDay(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1114 if(!(date
= date_this(jsthis
)))
1115 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1118 *r
= jsval_number(week_day(date
->time
));
1122 /* ECMA-262 3rd Edition 15.9.5.18 */
1123 static HRESULT
Date_getHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1130 if(!(date
= date_this(jsthis
)))
1131 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1134 *r
= jsval_number(hour_from_time(local_time(date
->time
, date
)));
1138 /* ECMA-262 3rd Edition 15.9.5.19 */
1139 static HRESULT
Date_getUTCHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1146 if(!(date
= date_this(jsthis
)))
1147 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1150 *r
= jsval_number(hour_from_time(date
->time
));
1154 /* ECMA-262 3rd Edition 15.9.5.20 */
1155 static HRESULT
Date_getMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1162 if(!(date
= date_this(jsthis
)))
1163 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1166 *r
= jsval_number(min_from_time(local_time(date
->time
, date
)));
1170 /* ECMA-262 3rd Edition 15.9.5.21 */
1171 static HRESULT
Date_getUTCMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1178 if(!(date
= date_this(jsthis
)))
1179 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1182 *r
= jsval_number(min_from_time(date
->time
));
1186 /* ECMA-262 3rd Edition 15.9.5.22 */
1187 static HRESULT
Date_getSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
, jsval_t
*r
)
1193 if(!(date
= date_this(jsthis
)))
1194 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1197 *r
= jsval_number(sec_from_time(local_time(date
->time
, date
)));
1201 /* ECMA-262 3rd Edition 15.9.5.23 */
1202 static HRESULT
Date_getUTCSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1209 if(!(date
= date_this(jsthis
)))
1210 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1213 *r
= jsval_number(sec_from_time(date
->time
));
1217 /* ECMA-262 3rd Edition 15.9.5.24 */
1218 static HRESULT
Date_getMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1225 if(!(date
= date_this(jsthis
)))
1226 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1229 *r
= jsval_number(ms_from_time(local_time(date
->time
, date
)));
1233 /* ECMA-262 3rd Edition 15.9.5.25 */
1234 static HRESULT
Date_getUTCMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1241 if(!(date
= date_this(jsthis
)))
1242 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1245 *r
= jsval_number(ms_from_time(date
->time
));
1249 /* ECMA-262 3rd Edition 15.9.5.26 */
1250 static HRESULT
Date_getTimezoneOffset(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1257 if(!(date
= date_this(jsthis
)))
1258 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1261 *r
= jsval_number(floor((date
->time
-local_time(date
->time
, date
))/MS_PER_MINUTE
));
1265 /* ECMA-262 3rd Edition 15.9.5.27 */
1266 static HRESULT
Date_setTime(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1275 if(!(date
= date_this(jsthis
)))
1276 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1279 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1281 hres
= to_number(ctx
, argv
[0], &n
);
1285 date
->time
= time_clip(n
);
1288 *r
= jsval_number(date
->time
);
1292 /* ECMA-262 3rd Edition 15.9.5.28 */
1293 static HRESULT
Date_setMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1302 if(!(date
= date_this(jsthis
)))
1303 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1306 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1308 hres
= to_number(ctx
, argv
[0], &n
);
1312 t
= local_time(date
->time
, date
);
1313 t
= make_date(day(t
), make_time(hour_from_time(t
), min_from_time(t
),
1314 sec_from_time(t
), n
));
1315 date
->time
= time_clip(utc(t
, date
));
1318 *r
= jsval_number(date
->time
);
1322 /* ECMA-262 3rd Edition 15.9.5.29 */
1323 static HRESULT
Date_setUTCMilliseconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1332 if(!(date
= date_this(jsthis
)))
1333 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1336 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1338 hres
= to_number(ctx
, argv
[0], &n
);
1343 t
= make_date(day(t
), make_time(hour_from_time(t
), min_from_time(t
),
1344 sec_from_time(t
), n
));
1345 date
->time
= time_clip(t
);
1348 *r
= jsval_number(date
->time
);
1352 /* ECMA-262 3rd Edition 15.9.5.30 */
1353 static HRESULT
Date_setSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1362 if(!(date
= date_this(jsthis
)))
1363 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1366 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1368 t
= local_time(date
->time
, date
);
1370 hres
= to_number(ctx
, argv
[0], &sec
);
1375 hres
= to_number(ctx
, argv
[1], &ms
);
1379 ms
= ms_from_time(t
);
1382 t
= make_date(day(t
), make_time(hour_from_time(t
),
1383 min_from_time(t
), sec
, ms
));
1384 date
->time
= time_clip(utc(t
, date
));
1387 *r
= jsval_number(date
->time
);
1391 /* ECMA-262 3rd Edition 15.9.5.31 */
1392 static HRESULT
Date_setUTCSeconds(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1401 if(!(date
= date_this(jsthis
)))
1402 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1405 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1409 hres
= to_number(ctx
, argv
[0], &sec
);
1414 hres
= to_number(ctx
, argv
[1], &ms
);
1418 ms
= ms_from_time(t
);
1421 t
= make_date(day(t
), make_time(hour_from_time(t
),
1422 min_from_time(t
), sec
, ms
));
1423 date
->time
= time_clip(t
);
1426 *r
= jsval_number(date
->time
);
1430 /* ECMA-262 3rd Edition 15.9.5.33 */
1431 static HRESULT
Date_setMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1435 double t
, min
, sec
, ms
;
1440 if(!(date
= date_this(jsthis
)))
1441 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1444 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1446 t
= local_time(date
->time
, date
);
1448 hres
= to_number(ctx
, argv
[0], &min
);
1453 hres
= to_number(ctx
, argv
[1], &sec
);
1457 sec
= sec_from_time(t
);
1461 hres
= to_number(ctx
, argv
[2], &ms
);
1465 ms
= ms_from_time(t
);
1468 t
= make_date(day(t
), make_time(hour_from_time(t
),
1470 date
->time
= time_clip(utc(t
, date
));
1473 *r
= jsval_number(date
->time
);
1477 /* ECMA-262 3rd Edition 15.9.5.34 */
1478 static HRESULT
Date_setUTCMinutes(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1482 double t
, min
, sec
, ms
;
1487 if(!(date
= date_this(jsthis
)))
1488 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1491 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1495 hres
= to_number(ctx
, argv
[0], &min
);
1500 hres
= to_number(ctx
, argv
[1], &sec
);
1504 sec
= sec_from_time(t
);
1508 hres
= to_number(ctx
, argv
[2], &ms
);
1512 ms
= ms_from_time(t
);
1515 t
= make_date(day(t
), make_time(hour_from_time(t
),
1517 date
->time
= time_clip(t
);
1520 *r
= jsval_number(date
->time
);
1524 /* ECMA-262 3rd Edition 15.9.5.35 */
1525 static HRESULT
Date_setHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1529 double t
, hour
, min
, sec
, ms
;
1534 if(!(date
= date_this(jsthis
)))
1535 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1538 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1540 t
= local_time(date
->time
, date
);
1542 hres
= to_number(ctx
, argv
[0], &hour
);
1547 hres
= to_number(ctx
, argv
[1], &min
);
1551 min
= min_from_time(t
);
1555 hres
= to_number(ctx
, argv
[2], &sec
);
1559 sec
= sec_from_time(t
);
1563 hres
= to_number(ctx
, argv
[3], &ms
);
1567 ms
= ms_from_time(t
);
1570 t
= make_date(day(t
), make_time(hour
, min
, sec
, ms
));
1571 date
->time
= time_clip(utc(t
, date
));
1574 *r
= jsval_number(date
->time
);
1578 /* ECMA-262 3rd Edition 15.9.5.36 */
1579 static HRESULT
Date_setUTCHours(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1583 double t
, hour
, min
, sec
, ms
;
1588 if(!(date
= date_this(jsthis
)))
1589 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1592 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1596 hres
= to_number(ctx
, argv
[0], &hour
);
1601 hres
= to_number(ctx
, argv
[1], &min
);
1605 min
= min_from_time(t
);
1609 hres
= to_number(ctx
, argv
[2], &sec
);
1613 sec
= sec_from_time(t
);
1617 hres
= to_number(ctx
, argv
[3], &ms
);
1621 ms
= ms_from_time(t
);
1624 t
= make_date(day(t
), make_time(hour
, min
, sec
, ms
));
1625 date
->time
= time_clip(t
);
1628 *r
= jsval_number(date
->time
);
1632 /* ECMA-262 3rd Edition 15.9.5.36 */
1633 static HRESULT
Date_setDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1642 if(!(date
= date_this(jsthis
)))
1643 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1646 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1648 hres
= to_number(ctx
, argv
[0], &n
);
1652 t
= local_time(date
->time
, date
);
1653 t
= make_date(make_day(year_from_time(t
), month_from_time(t
), n
), time_within_day(t
));
1654 date
->time
= time_clip(utc(t
, date
));
1657 *r
= jsval_number(date
->time
);
1661 /* ECMA-262 3rd Edition 15.9.5.37 */
1662 static HRESULT
Date_setUTCDate(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1671 if(!(date
= date_this(jsthis
)))
1672 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1675 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1677 hres
= to_number(ctx
, argv
[0], &n
);
1682 t
= make_date(make_day(year_from_time(t
), month_from_time(t
), n
), time_within_day(t
));
1683 date
->time
= time_clip(t
);
1686 *r
= jsval_number(date
->time
);
1690 /* ECMA-262 3rd Edition 15.9.5.38 */
1691 static HRESULT
Date_setMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1695 DOUBLE t
, month
, ddate
;
1700 if(!(date
= date_this(jsthis
)))
1701 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1704 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1706 t
= local_time(date
->time
, date
);
1708 hres
= to_number(ctx
, argv
[0], &month
);
1713 hres
= to_number(ctx
, argv
[1], &ddate
);
1717 ddate
= date_from_time(t
);
1720 t
= make_date(make_day(year_from_time(t
), month
, ddate
),
1721 time_within_day(t
));
1722 date
->time
= time_clip(utc(t
, date
));
1725 *r
= jsval_number(date
->time
);
1729 /* ECMA-262 3rd Edition 15.9.5.39 */
1730 static HRESULT
Date_setUTCMonth(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1734 double t
, month
, ddate
;
1739 if(!(date
= date_this(jsthis
)))
1740 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1743 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1747 hres
= to_number(ctx
, argv
[0], &month
);
1752 hres
= to_number(ctx
, argv
[1], &ddate
);
1756 ddate
= date_from_time(t
);
1759 t
= make_date(make_day(year_from_time(t
), month
, ddate
),
1760 time_within_day(t
));
1761 date
->time
= time_clip(t
);
1764 *r
= jsval_number(date
->time
);
1768 /* ECMA-262 3rd Edition 15.9.5.40 */
1769 static HRESULT
Date_setFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1773 double t
, year
, month
, ddate
;
1778 if(!(date
= date_this(jsthis
)))
1779 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1782 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1784 t
= local_time(date
->time
, date
);
1786 hres
= to_number(ctx
, argv
[0], &year
);
1791 hres
= to_number(ctx
, argv
[1], &month
);
1795 month
= month_from_time(t
);
1799 hres
= to_number(ctx
, argv
[2], &ddate
);
1803 ddate
= date_from_time(t
);
1806 t
= make_date(make_day(year
, month
, ddate
), time_within_day(t
));
1807 date
->time
= time_clip(utc(t
, date
));
1810 *r
= jsval_number(date
->time
);
1814 /* ECMA-262 3rd Edition 15.9.5.41 */
1815 static HRESULT
Date_setUTCFullYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1819 double t
, year
, month
, ddate
;
1824 if(!(date
= date_this(jsthis
)))
1825 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1828 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1832 hres
= to_number(ctx
, argv
[0], &year
);
1837 hres
= to_number(ctx
, argv
[1], &month
);
1841 month
= month_from_time(t
);
1845 hres
= to_number(ctx
, argv
[2], &ddate
);
1849 ddate
= date_from_time(t
);
1852 t
= make_date(make_day(year
, month
, ddate
), time_within_day(t
));
1853 date
->time
= time_clip(t
);
1856 *r
= jsval_number(date
->time
);
1860 /* ECMA-262 3rd Edition B2.4 */
1861 static HRESULT
Date_getYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1869 if(!(date
= date_this(jsthis
)))
1870 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1872 t
= local_time(date
->time
, date
);
1875 *r
= jsval_number(NAN
);
1879 year
= year_from_time(t
);
1881 *r
= jsval_number((1900<=year
&& year
<2000)?year
-1900:year
);
1885 /* ECMA-262 3rd Edition B2.5 */
1886 static HRESULT
Date_setYear(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
1895 if(!(date
= date_this(jsthis
)))
1896 return throw_type_error(ctx
, JS_E_DATE_EXPECTED
, NULL
);
1899 return throw_type_error(ctx
, JS_E_MISSING_ARG
, NULL
);
1901 t
= local_time(date
->time
, date
);
1903 hres
= to_number(ctx
, argv
[0], &year
);
1910 *r
= jsval_number(NAN
);
1914 year
= year
>= 0.0 ? floor(year
) : -floor(-year
);
1915 if(-1.0 < year
&& year
< 100.0)
1918 date
->time
= time_clip(utc(make_date(make_day(year
, month_from_time(t
), date_from_time(t
)), time_within_day(t
)), date
));
1921 *r
= jsval_number(date
->time
);
1925 static HRESULT
Date_get_value(script_ctx_t
*ctx
, jsdisp_t
*jsthis
, jsval_t
*r
)
1929 return dateobj_to_string(date_from_jsdisp(jsthis
), r
);
1932 static const builtin_prop_t Date_props
[] = {
1933 {getDateW
, Date_getDate
, PROPF_METHOD
},
1934 {getDayW
, Date_getDay
, PROPF_METHOD
},
1935 {getFullYearW
, Date_getFullYear
, PROPF_METHOD
},
1936 {getHoursW
, Date_getHours
, PROPF_METHOD
},
1937 {getMillisecondsW
, Date_getMilliseconds
, PROPF_METHOD
},
1938 {getMinutesW
, Date_getMinutes
, PROPF_METHOD
},
1939 {getMonthW
, Date_getMonth
, PROPF_METHOD
},
1940 {getSecondsW
, Date_getSeconds
, PROPF_METHOD
},
1941 {getTimeW
, Date_getTime
, PROPF_METHOD
},
1942 {getTimezoneOffsetW
, Date_getTimezoneOffset
, PROPF_METHOD
},
1943 {getUTCDateW
, Date_getUTCDate
, PROPF_METHOD
},
1944 {getUTCDayW
, Date_getUTCDay
, PROPF_METHOD
},
1945 {getUTCFullYearW
, Date_getUTCFullYear
, PROPF_METHOD
},
1946 {getUTCHoursW
, Date_getUTCHours
, PROPF_METHOD
},
1947 {getUTCMillisecondsW
, Date_getUTCMilliseconds
, PROPF_METHOD
},
1948 {getUTCMinutesW
, Date_getUTCMinutes
, PROPF_METHOD
},
1949 {getUTCMonthW
, Date_getUTCMonth
, PROPF_METHOD
},
1950 {getUTCSecondsW
, Date_getUTCSeconds
, PROPF_METHOD
},
1951 {getYearW
, Date_getYear
, PROPF_METHOD
},
1952 {setDateW
, Date_setDate
, PROPF_METHOD
|1},
1953 {setFullYearW
, Date_setFullYear
, PROPF_METHOD
|3},
1954 {setHoursW
, Date_setHours
, PROPF_METHOD
|4},
1955 {setMillisecondsW
, Date_setMilliseconds
, PROPF_METHOD
|1},
1956 {setMinutesW
, Date_setMinutes
, PROPF_METHOD
|3},
1957 {setMonthW
, Date_setMonth
, PROPF_METHOD
|2},
1958 {setSecondsW
, Date_setSeconds
, PROPF_METHOD
|2},
1959 {setTimeW
, Date_setTime
, PROPF_METHOD
|1},
1960 {setUTCDateW
, Date_setUTCDate
, PROPF_METHOD
|1},
1961 {setUTCFullYearW
, Date_setUTCFullYear
, PROPF_METHOD
|3},
1962 {setUTCHoursW
, Date_setUTCHours
, PROPF_METHOD
|4},
1963 {setUTCMillisecondsW
, Date_setUTCMilliseconds
, PROPF_METHOD
|1},
1964 {setUTCMinutesW
, Date_setUTCMinutes
, PROPF_METHOD
|3},
1965 {setUTCMonthW
, Date_setUTCMonth
, PROPF_METHOD
|2},
1966 {setUTCSecondsW
, Date_setUTCSeconds
, PROPF_METHOD
|2},
1967 {setYearW
, Date_setYear
, PROPF_METHOD
|1},
1968 {toDateStringW
, Date_toDateString
, PROPF_METHOD
},
1969 {toGMTStringW
, Date_toGMTString
, PROPF_METHOD
},
1970 {toLocaleDateStringW
, Date_toLocaleDateString
, PROPF_METHOD
},
1971 {toLocaleStringW
, Date_toLocaleString
, PROPF_METHOD
},
1972 {toLocaleTimeStringW
, Date_toLocaleTimeString
, PROPF_METHOD
},
1973 {toStringW
, Date_toString
, PROPF_METHOD
},
1974 {toTimeStringW
, Date_toTimeString
, PROPF_METHOD
},
1975 {toUTCStringW
, Date_toUTCString
, PROPF_METHOD
},
1976 {valueOfW
, Date_valueOf
, PROPF_METHOD
},
1979 static const builtin_info_t Date_info
= {
1981 {NULL
, NULL
,0, Date_get_value
},
1982 sizeof(Date_props
)/sizeof(*Date_props
),
1988 static const builtin_info_t DateInst_info
= {
1990 {NULL
, NULL
,0, Date_get_value
},
1996 static HRESULT
create_date(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
, DOUBLE time
, jsdisp_t
**ret
)
2000 TIME_ZONE_INFORMATION tzi
;
2002 GetTimeZoneInformation(&tzi
);
2004 date
= heap_alloc_zero(sizeof(DateInstance
));
2006 return E_OUTOFMEMORY
;
2008 if(object_prototype
)
2009 hres
= init_dispex(&date
->dispex
, ctx
, &Date_info
, object_prototype
);
2011 hres
= init_dispex_from_constr(&date
->dispex
, ctx
, &DateInst_info
, ctx
->date_constr
);
2018 date
->bias
= tzi
.Bias
;
2019 date
->standardDate
= tzi
.StandardDate
;
2020 date
->standardBias
= tzi
.StandardBias
;
2021 date
->daylightDate
= tzi
.DaylightDate
;
2022 date
->daylightBias
= tzi
.DaylightBias
;
2024 *ret
= &date
->dispex
;
2028 static inline HRESULT
date_parse(jsstr_t
*input_str
, double *ret
) {
2029 static const DWORD string_ids
[] = { LOCALE_SMONTHNAME12
, LOCALE_SMONTHNAME11
,
2030 LOCALE_SMONTHNAME10
, LOCALE_SMONTHNAME9
, LOCALE_SMONTHNAME8
,
2031 LOCALE_SMONTHNAME7
, LOCALE_SMONTHNAME6
, LOCALE_SMONTHNAME5
,
2032 LOCALE_SMONTHNAME4
, LOCALE_SMONTHNAME3
, LOCALE_SMONTHNAME2
,
2033 LOCALE_SMONTHNAME1
, LOCALE_SDAYNAME7
, LOCALE_SDAYNAME1
,
2034 LOCALE_SDAYNAME2
, LOCALE_SDAYNAME3
, LOCALE_SDAYNAME4
,
2035 LOCALE_SDAYNAME5
, LOCALE_SDAYNAME6
};
2036 WCHAR
*strings
[sizeof(string_ids
)/sizeof(DWORD
)];
2038 int input_len
, parse_len
= 0, nest_level
= 0, i
, size
;
2039 int year
= 0, month
= 0, day
= 0, hour
= 0, min
= 0, sec
= 0;
2040 int ms
= 0, offset
= 0, hour_adjust
= 0;
2041 BOOL set_year
= FALSE
, set_month
= FALSE
, set_day
= FALSE
, set_hour
= FALSE
;
2042 BOOL set_offset
= FALSE
, set_era
= FALSE
, ad
= TRUE
, set_am
= FALSE
, am
= TRUE
;
2043 BOOL set_hour_adjust
= TRUE
;
2044 TIME_ZONE_INFORMATION tzi
;
2049 input_len
= jsstr_length(input_str
);
2050 input
= jsstr_flatten(input_str
);
2052 return E_OUTOFMEMORY
;
2054 for(i
=0; i
<input_len
; i
++) {
2055 if(input
[i
] == '(') nest_level
++;
2056 else if(input
[i
] == ')') {
2063 else if(!nest_level
) parse_len
++;
2066 parse
= heap_alloc((parse_len
+1)*sizeof(WCHAR
));
2068 return E_OUTOFMEMORY
;
2071 for(i
=0; i
<input_len
; i
++) {
2072 if(input
[i
] == '(') nest_level
++;
2073 else if(input
[i
] == ')') nest_level
--;
2074 else if(!nest_level
) parse
[parse_len
++] = toupperW(input
[i
]);
2076 parse
[parse_len
] = 0;
2078 GetTimeZoneInformation(&tzi
);
2080 di
.standardDate
= tzi
.StandardDate
;
2081 di
.standardBias
= tzi
.StandardBias
;
2082 di
.daylightDate
= tzi
.DaylightDate
;
2083 di
.daylightBias
= tzi
.DaylightBias
;
2085 /* FIXME: Cache strings */
2086 lcid_en
= MAKELCID(MAKELANGID(LANG_ENGLISH
,SUBLANG_ENGLISH_US
),SORT_DEFAULT
);
2087 for(i
=0; i
<sizeof(string_ids
)/sizeof(DWORD
); i
++) {
2088 size
= GetLocaleInfoW(lcid_en
, string_ids
[i
], NULL
, 0);
2089 strings
[i
] = heap_alloc((size
+1)*sizeof(WCHAR
));
2093 heap_free(strings
[i
]);
2095 return E_OUTOFMEMORY
;
2097 GetLocaleInfoW(lcid_en
, string_ids
[i
], strings
[i
], size
);
2100 for(i
=0; i
<parse_len
;) {
2101 while(isspaceW(parse
[i
])) i
++;
2102 if(parse
[i
] == ',') {
2103 while(parse
[i
] == ',') i
++;
2107 if(parse
[i
]>='0' && parse
[i
]<='9') {
2108 int tmp
= atoiW(&parse
[i
]);
2109 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2110 while(isspaceW(parse
[i
])) i
++;
2112 if(parse
[i
] == ':') {
2119 while(parse
[i
] == ':') i
++;
2120 while(isspaceW(parse
[i
])) i
++;
2121 if(parse
[i
]>='0' && parse
[i
]<='9') {
2122 min
= atoiW(&parse
[i
]);
2123 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2126 while(isspaceW(parse
[i
])) i
++;
2127 while(parse
[i
] == ':') i
++;
2128 while(isspaceW(parse
[i
])) i
++;
2129 if(parse
[i
]>='0' && parse
[i
]<='9') {
2130 sec
= atoiW(&parse
[i
]);
2131 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2134 else if(parse
[i
]=='-' || parse
[i
]=='/') {
2135 /* Short or long date */
2136 if(set_day
|| set_month
|| set_year
) break;
2143 while(isspaceW(parse
[i
])) i
++;
2144 while(parse
[i
]=='-' || parse
[i
]=='/') i
++;
2145 while(isspaceW(parse
[i
])) i
++;
2146 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2147 day
= atoiW(&parse
[i
]);
2148 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2150 while(parse
[i
]=='-' || parse
[i
]=='/') i
++;
2151 while(isspaceW(parse
[i
])) i
++;
2152 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2153 year
= atoiW(&parse
[i
]);
2154 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2163 else if(tmp
<0) break;
2177 else if(parse
[i
]=='+' || parse
[i
]=='-') {
2178 /* Timezone offset */
2179 BOOL positive
= TRUE
;
2181 if(set_offset
&& set_hour_adjust
) break;
2183 set_hour_adjust
= FALSE
;
2185 if(parse
[i
] == '-') positive
= FALSE
;
2188 while(isspaceW(parse
[i
])) i
++;
2189 if(parse
[i
]<'0' || parse
[i
]>'9') break;
2190 offset
= atoiW(&parse
[i
]);
2191 while(parse
[i
]>='0' && parse
[i
]<='9') i
++;
2193 if(offset
<24) offset
*= 60;
2194 else offset
= (offset
/100)*60 + offset
%100;
2196 if(positive
) offset
= -offset
;
2200 if(parse
[i
]<'A' || parse
[i
]>'Z') break;
2201 else if(parse
[i
]=='B' && (parse
[i
+1]=='C' ||
2202 (parse
[i
+1]=='.' && parse
[i
+2]=='C'))) {
2209 if(parse
[i
] == '.') i
++;
2211 if(parse
[i
] == '.') i
++;
2213 else if(parse
[i
]=='A' && (parse
[i
+1]=='D' ||
2214 (parse
[i
+1]=='.' && parse
[i
+2]=='D'))) {
2220 if(parse
[i
] == '.') i
++;
2222 if(parse
[i
] == '.') i
++;
2224 else if(parse
[i
+1]<'A' || parse
[i
+1]>'Z') {
2226 if(set_offset
) break;
2229 if(parse
[i
] <= 'I') hour_adjust
= parse
[i
]-'A'+2;
2230 else if(parse
[i
] == 'J') break;
2231 else if(parse
[i
] <= 'M') hour_adjust
= parse
[i
]-'K'+11;
2232 else if(parse
[i
] <= 'Y') hour_adjust
= parse
[i
]-'N';
2233 else hour_adjust
= 1;
2236 if(parse
[i
] == '.') i
++;
2238 else if(parse
[i
]=='A' && parse
[i
+1]=='M') {
2245 else if(parse
[i
]=='P' && parse
[i
+1]=='M') {
2252 else if((parse
[i
]=='U' && parse
[i
+1]=='T' && parse
[i
+2]=='C')
2253 || (parse
[i
]=='G' && parse
[i
+1]=='M' && parse
[i
+2]=='T')) {
2255 if(set_offset
) break;
2257 set_hour_adjust
= FALSE
;
2262 /* Month or garbage */
2265 for(size
=i
; parse
[size
]>='A' && parse
[size
]<='Z'; size
++);
2268 for(j
=0; j
<sizeof(string_ids
)/sizeof(DWORD
); j
++)
2269 if(!strncmpiW(&parse
[i
], strings
[j
], size
)) break;
2272 if(set_month
) break;
2276 else if(j
== sizeof(string_ids
)/sizeof(DWORD
)) break;
2283 if(i
== parse_len
&& set_year
&& set_month
&& set_day
&& (!set_am
|| hour
<13)) {
2285 if(hour
== 12) hour
= 0;
2289 if(!ad
) year
= -year
+1;
2290 else if(year
<100) year
+= 1900;
2292 *ret
= time_clip(make_date(make_day(year
, month
, day
),
2293 make_time(hour
+hour_adjust
, min
, sec
, ms
)) + offset
*MS_PER_MINUTE
);
2296 *ret
= utc(*ret
, &di
);
2301 for(i
=0; i
<sizeof(string_ids
)/sizeof(DWORD
); i
++)
2302 heap_free(strings
[i
]);
2308 static HRESULT
DateConstr_parse(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2319 *r
= jsval_number(NAN
);
2323 hres
= to_string(ctx
, argv
[0], &parse_str
);
2327 hres
= date_parse(parse_str
, &n
);
2328 jsstr_release(parse_str
);
2332 *r
= jsval_number(n
);
2336 static HRESULT
date_utc(script_ctx_t
*ctx
, unsigned argc
, jsval_t
*argv
, double *ret
)
2338 double year
, month
, vdate
, hours
, minutes
, seconds
, ms
;
2344 hres
= to_number(ctx
, argv
[0], &year
);
2347 if(0 <= year
&& year
<= 99)
2354 hres
= to_number(ctx
, argv
[1], &month
);
2362 hres
= to_number(ctx
, argv
[2], &vdate
);
2370 hres
= to_number(ctx
, argv
[3], &hours
);
2378 hres
= to_number(ctx
, argv
[4], &minutes
);
2386 hres
= to_number(ctx
, argv
[5], &seconds
);
2394 hres
= to_number(ctx
, argv
[6], &ms
);
2401 *ret
= time_clip(make_date(make_day(year
, month
, vdate
),
2402 make_time(hours
, minutes
,seconds
, ms
)));
2406 static HRESULT
DateConstr_UTC(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2414 hres
= date_utc(ctx
, argc
, argv
, &n
);
2415 if(SUCCEEDED(hres
) && r
)
2416 *r
= jsval_number(n
);
2420 static HRESULT
DateConstr_value(script_ctx_t
*ctx
, vdisp_t
*jsthis
, WORD flags
, unsigned argc
, jsval_t
*argv
,
2429 case DISPATCH_CONSTRUCT
:
2431 /* ECMA-262 3rd Edition 15.9.3.3 */
2436 GetSystemTimeAsFileTime(&time
);
2437 lltime
= ((LONGLONG
)time
.dwHighDateTime
<<32)
2438 + time
.dwLowDateTime
;
2440 hres
= create_date(ctx
, NULL
, lltime
/10000-TIME_EPOCH
, &date
);
2446 /* ECMA-262 3rd Edition 15.9.3.2 */
2451 hres
= to_primitive(ctx
, argv
[0], &prim
, NO_HINT
);
2456 hres
= date_parse(get_string(prim
), &n
);
2458 hres
= to_number(ctx
, prim
, &n
);
2460 jsval_release(prim
);
2464 hres
= create_date(ctx
, NULL
, time_clip(n
), &date
);
2470 /* ECMA-262 3rd Edition 15.9.3.1 */
2475 hres
= date_utc(ctx
, argc
, argv
, &ret_date
);
2479 hres
= create_date(ctx
, NULL
, ret_date
, &date
);
2483 di
= (DateInstance
*)date
;
2484 di
->time
= utc(di
->time
, di
);
2488 *r
= jsval_obj(date
);
2492 FILETIME system_time
, local_time
;
2495 GetSystemTimeAsFileTime(&system_time
);
2496 FileTimeToLocalFileTime(&system_time
, &local_time
);
2497 lltime
= ((LONGLONG
)local_time
.dwHighDateTime
<<32)
2498 + local_time
.dwLowDateTime
;
2500 return date_to_string(lltime
/10000-TIME_EPOCH
, FALSE
, 0, r
);
2504 FIXME("unimplemented flags %x\n", flags
);
2511 static const builtin_prop_t DateConstr_props
[] = {
2512 {UTCW
, DateConstr_UTC
, PROPF_METHOD
},
2513 {parseW
, DateConstr_parse
, PROPF_METHOD
}
2516 static const builtin_info_t DateConstr_info
= {
2518 DEFAULT_FUNCTION_VALUE
,
2519 sizeof(DateConstr_props
)/sizeof(*DateConstr_props
),
2525 HRESULT
create_date_constr(script_ctx_t
*ctx
, jsdisp_t
*object_prototype
, jsdisp_t
**ret
)
2530 static const WCHAR DateW
[] = {'D','a','t','e',0};
2532 hres
= create_date(ctx
, object_prototype
, 0.0, &date
);
2536 hres
= create_builtin_constructor(ctx
, DateConstr_value
, DateW
, &DateConstr_info
,
2537 PROPF_CONSTR
|7, date
, ret
);
2539 jsdisp_release(date
);