2008-09-30 17:48:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
2009-07-06 11:00:22 +02:00
|
|
|
* Copyright 2009 Piotr Caban
|
2008-09-30 17:48:18 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2009-08-13 22:32:52 +02:00
|
|
|
|
2008-10-13 23:28:00 +02:00
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
2012-10-11 12:17:37 +02:00
|
|
|
#include <assert.h>
|
2008-10-13 23:28:00 +02:00
|
|
|
|
2008-09-30 17:48:18 +02:00
|
|
|
#include "jscript.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2009-06-04 22:36:27 +02:00
|
|
|
/* 1601 to 1970 is 369 years plus 89 leap days */
|
|
|
|
#define TIME_EPOCH ((ULONGLONG)(369 * 365 + 89) * 86400 * 1000)
|
|
|
|
|
2008-09-30 17:48:18 +02:00
|
|
|
typedef struct {
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t dispex;
|
2008-10-13 23:28:00 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 15.9.1.1 */
|
|
|
|
DOUBLE time;
|
2009-06-04 22:36:27 +02:00
|
|
|
|
|
|
|
LONG bias;
|
2009-06-22 20:40:01 +02:00
|
|
|
SYSTEMTIME standardDate;
|
|
|
|
LONG standardBias;
|
|
|
|
SYSTEMTIME daylightDate;
|
|
|
|
LONG daylightBias;
|
2008-09-30 17:48:18 +02:00
|
|
|
} DateInstance;
|
|
|
|
|
|
|
|
static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR toLocaleStringW[] = {'t','o','L','o','c','a','l','e','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR valueOfW[] = {'v','a','l','u','e','O','f',0};
|
2018-04-11 19:36:25 +02:00
|
|
|
static const WCHAR toISOStringW[] = {'t','o','I','S','O','S','t','r','i','n','g',0};
|
2008-09-30 17:48:18 +02:00
|
|
|
static const WCHAR toUTCStringW[] = {'t','o','U','T','C','S','t','r','i','n','g',0};
|
2009-10-06 13:11:25 +02:00
|
|
|
static const WCHAR toGMTStringW[] = {'t','o','G','M','T','S','t','r','i','n','g',0};
|
2008-09-30 17:48:18 +02:00
|
|
|
static const WCHAR toDateStringW[] = {'t','o','D','a','t','e','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR toTimeStringW[] = {'t','o','T','i','m','e','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR toLocaleDateStringW[] = {'t','o','L','o','c','a','l','e','D','a','t','e','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR toLocaleTimeStringW[] = {'t','o','L','o','c','a','l','e','T','i','m','e','S','t','r','i','n','g',0};
|
|
|
|
static const WCHAR getTimeW[] = {'g','e','t','T','i','m','e',0};
|
|
|
|
static const WCHAR getFullYearW[] = {'g','e','t','F','u','l','l','Y','e','a','r',0};
|
|
|
|
static const WCHAR getUTCFullYearW[] = {'g','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
|
|
|
|
static const WCHAR getMonthW[] = {'g','e','t','M','o','n','t','h',0};
|
|
|
|
static const WCHAR getUTCMonthW[] = {'g','e','t','U','T','C','M','o','n','t','h',0};
|
|
|
|
static const WCHAR getDateW[] = {'g','e','t','D','a','t','e',0};
|
|
|
|
static const WCHAR getUTCDateW[] = {'g','e','t','U','T','C','D','a','t','e',0};
|
|
|
|
static const WCHAR getDayW[] = {'g','e','t','D','a','y',0};
|
|
|
|
static const WCHAR getUTCDayW[] = {'g','e','t','U','T','C','D','a','y',0};
|
|
|
|
static const WCHAR getHoursW[] = {'g','e','t','H','o','u','r','s',0};
|
|
|
|
static const WCHAR getUTCHoursW[] = {'g','e','t','U','T','C','H','o','u','r','s',0};
|
|
|
|
static const WCHAR getMinutesW[] = {'g','e','t','M','i','n','u','t','e','s',0};
|
|
|
|
static const WCHAR getUTCMinutesW[] = {'g','e','t','U','T','C','M','i','n','u','t','e','s',0};
|
|
|
|
static const WCHAR getSecondsW[] = {'g','e','t','S','e','c','o','n','d','s',0};
|
|
|
|
static const WCHAR getUTCSecondsW[] = {'g','e','t','U','T','C','S','e','c','o','n','d','s',0};
|
2009-06-16 11:42:04 +02:00
|
|
|
static const WCHAR getMillisecondsW[] = {'g','e','t','M','i','l','l','i','s','e','c','o','n','d','s',0};
|
|
|
|
static const WCHAR getUTCMillisecondsW[] = {'g','e','t','U','T','C','M','i','l','l','i','s','e','c','o','n','d','s',0};
|
2008-09-30 17:48:18 +02:00
|
|
|
static const WCHAR getTimezoneOffsetW[] = {'g','e','t','T','i','m','e','z','o','n','e','O','f','f','s','e','t',0};
|
|
|
|
static const WCHAR setTimeW[] = {'s','e','t','T','i','m','e',0};
|
2009-06-16 11:42:04 +02:00
|
|
|
static const WCHAR setMillisecondsW[] = {'s','e','t','M','i','l','l','i','s','e','c','o','n','d','s',0};
|
|
|
|
static const WCHAR setUTCMillisecondsW[] = {'s','e','t','U','T','C','M','i','l','l','i','s','e','c','o','n','d','s',0};
|
2008-09-30 17:48:18 +02:00
|
|
|
static const WCHAR setSecondsW[] = {'s','e','t','S','e','c','o','n','d','s',0};
|
|
|
|
static const WCHAR setUTCSecondsW[] = {'s','e','t','U','T','C','S','e','c','o','n','d','s',0};
|
|
|
|
static const WCHAR setMinutesW[] = {'s','e','t','M','i','n','u','t','e','s',0};
|
|
|
|
static const WCHAR setUTCMinutesW[] = {'s','e','t','U','T','C','M','i','n','u','t','e','s',0};
|
|
|
|
static const WCHAR setHoursW[] = {'s','e','t','H','o','u','r','s',0};
|
2009-06-16 11:42:27 +02:00
|
|
|
static const WCHAR setUTCHoursW[] = {'s','e','t','U','T','C','H','o','u','r','s',0};
|
2008-09-30 17:48:18 +02:00
|
|
|
static const WCHAR setDateW[] = {'s','e','t','D','a','t','e',0};
|
|
|
|
static const WCHAR setUTCDateW[] = {'s','e','t','U','T','C','D','a','t','e',0};
|
|
|
|
static const WCHAR setMonthW[] = {'s','e','t','M','o','n','t','h',0};
|
|
|
|
static const WCHAR setUTCMonthW[] = {'s','e','t','U','T','C','M','o','n','t','h',0};
|
|
|
|
static const WCHAR setFullYearW[] = {'s','e','t','F','u','l','l','Y','e','a','r',0};
|
|
|
|
static const WCHAR setUTCFullYearW[] = {'s','e','t','U','T','C','F','u','l','l','Y','e','a','r',0};
|
2009-07-14 01:37:11 +02:00
|
|
|
static const WCHAR getYearW[] = {'g','e','t','Y','e','a','r',0};
|
2010-11-06 21:29:19 +01:00
|
|
|
static const WCHAR setYearW[] = {'s','e','t','Y','e','a','r',0};
|
2008-09-30 17:48:18 +02:00
|
|
|
|
2009-07-03 02:45:12 +02:00
|
|
|
static const WCHAR UTCW[] = {'U','T','C',0};
|
2018-03-01 19:18:49 +01:00
|
|
|
static const WCHAR nowW[] = {'n','o','w',0};
|
2009-07-03 02:45:12 +02:00
|
|
|
static const WCHAR parseW[] = {'p','a','r','s','e',0};
|
|
|
|
|
2015-02-06 12:09:40 +01:00
|
|
|
static inline DateInstance *date_from_jsdisp(jsdisp_t *jsdisp)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(jsdisp, DateInstance, dispex);
|
|
|
|
}
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
static inline DateInstance *date_this(vdisp_t *jsthis)
|
|
|
|
{
|
2015-02-06 12:09:40 +01:00
|
|
|
return is_vclass(jsthis, JSCLASS_DATE) ? date_from_jsdisp(jsthis->u.jsdisp) : NULL;
|
2009-09-23 16:18:39 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/*ECMA-262 3rd Edition 15.9.1.2 */
|
2009-06-09 14:01:01 +02:00
|
|
|
#define MS_PER_DAY 86400000
|
2009-06-09 15:39:18 +02:00
|
|
|
#define MS_PER_HOUR 3600000
|
2009-06-09 14:01:01 +02:00
|
|
|
#define MS_PER_MINUTE 60000
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.2 */
|
2009-06-09 14:02:42 +02:00
|
|
|
static inline DOUBLE day(DOUBLE time)
|
|
|
|
{
|
|
|
|
return floor(time / MS_PER_DAY);
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:41:50 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.2 */
|
|
|
|
static inline DOUBLE time_within_day(DOUBLE time)
|
|
|
|
{
|
|
|
|
DOUBLE ret;
|
|
|
|
|
|
|
|
ret = fmod(time, MS_PER_DAY);
|
|
|
|
if(ret < 0)
|
|
|
|
ret += MS_PER_DAY;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.3 */
|
2009-06-09 14:02:42 +02:00
|
|
|
static inline DOUBLE days_in_year(DOUBLE year)
|
|
|
|
{
|
|
|
|
int y;
|
|
|
|
|
|
|
|
if(year != (int)year)
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-09 14:02:42 +02:00
|
|
|
|
|
|
|
y = year;
|
|
|
|
if(y%4 != 0) return 365;
|
|
|
|
if(y%100 != 0) return 366;
|
|
|
|
if(y%400 != 0) return 365;
|
|
|
|
return 366;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.3 */
|
2009-06-09 14:01:01 +02:00
|
|
|
static inline DOUBLE day_from_year(DOUBLE year)
|
|
|
|
{
|
|
|
|
if(year != (int)year)
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-09 14:01:01 +02:00
|
|
|
|
2009-06-22 20:40:01 +02:00
|
|
|
return floor(365.0*(year-1970) + floor((year-1969)/4)
|
|
|
|
- floor((year-1901)/100) + floor((year-1601)/400));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int day_from_month(int month, int in_leap_year)
|
|
|
|
{
|
|
|
|
switch(month)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
return 31;
|
|
|
|
case 2:
|
|
|
|
return 59+in_leap_year;
|
|
|
|
case 3:
|
|
|
|
return 90+in_leap_year;
|
|
|
|
case 4:
|
|
|
|
return 120+in_leap_year;
|
|
|
|
case 5:
|
|
|
|
return 151+in_leap_year;
|
|
|
|
case 6:
|
|
|
|
return 181+in_leap_year;
|
|
|
|
case 7:
|
|
|
|
return 212+in_leap_year;
|
|
|
|
case 8:
|
|
|
|
return 243+in_leap_year;
|
|
|
|
case 9:
|
|
|
|
return 273+in_leap_year;
|
|
|
|
case 10:
|
|
|
|
return 304+in_leap_year;
|
|
|
|
default:
|
|
|
|
return 334+in_leap_year;
|
|
|
|
}
|
2009-06-09 14:01:01 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.3 */
|
2009-06-09 14:01:01 +02:00
|
|
|
static inline DOUBLE time_from_year(DOUBLE year)
|
|
|
|
{
|
|
|
|
return MS_PER_DAY*day_from_year(year);
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.3 */
|
2009-06-09 14:01:01 +02:00
|
|
|
static inline DOUBLE year_from_time(DOUBLE time)
|
|
|
|
{
|
|
|
|
int y;
|
|
|
|
|
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-09 14:01:01 +02:00
|
|
|
|
|
|
|
y = 1970 + time/365.25/MS_PER_DAY;
|
|
|
|
|
|
|
|
if(time_from_year(y) > time)
|
|
|
|
while(time_from_year(y) > time) y--;
|
|
|
|
else
|
|
|
|
while(time_from_year(y+1)<=time) y++;
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.3 */
|
2009-06-09 14:02:42 +02:00
|
|
|
static inline int in_leap_year(DOUBLE time)
|
|
|
|
{
|
|
|
|
if(days_in_year(year_from_time(time))==366)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.4 */
|
2009-06-09 14:02:42 +02:00
|
|
|
static inline int day_within_year(DOUBLE time)
|
|
|
|
{
|
|
|
|
return day(time) - day_from_year(year_from_time(time));
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.4 */
|
2009-06-09 14:02:42 +02:00
|
|
|
static inline DOUBLE month_from_time(DOUBLE time)
|
|
|
|
{
|
|
|
|
int ily = in_leap_year(time);
|
|
|
|
int dwy = day_within_year(time);
|
|
|
|
|
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-09 14:02:42 +02:00
|
|
|
|
|
|
|
if(0<=dwy && dwy<31) return 0;
|
|
|
|
if(dwy < 59+ily) return 1;
|
|
|
|
if(dwy < 90+ily) return 2;
|
|
|
|
if(dwy < 120+ily) return 3;
|
|
|
|
if(dwy < 151+ily) return 4;
|
|
|
|
if(dwy < 181+ily) return 5;
|
|
|
|
if(dwy < 212+ily) return 6;
|
|
|
|
if(dwy < 243+ily) return 7;
|
|
|
|
if(dwy < 273+ily) return 8;
|
|
|
|
if(dwy < 304+ily) return 9;
|
|
|
|
if(dwy < 334+ily) return 10;
|
|
|
|
return 11;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.5 */
|
2009-06-09 14:04:09 +02:00
|
|
|
static inline DOUBLE date_from_time(DOUBLE time)
|
|
|
|
{
|
|
|
|
int dwy = day_within_year(time);
|
|
|
|
int ily = in_leap_year(time);
|
|
|
|
int mft = month_from_time(time);
|
|
|
|
|
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-09 14:04:09 +02:00
|
|
|
|
|
|
|
if(mft==0) return dwy+1;
|
|
|
|
if(mft==1) return dwy-30;
|
|
|
|
if(mft==2) return dwy-58-ily;
|
|
|
|
if(mft==3) return dwy-89-ily;
|
|
|
|
if(mft==4) return dwy-119-ily;
|
|
|
|
if(mft==5) return dwy-150-ily;
|
|
|
|
if(mft==6) return dwy-180-ily;
|
|
|
|
if(mft==7) return dwy-211-ily;
|
|
|
|
if(mft==8) return dwy-242-ily;
|
|
|
|
if(mft==9) return dwy-272-ily;
|
|
|
|
if(mft==10) return dwy-303-ily;
|
|
|
|
return dwy-333-ily;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.6 */
|
2009-06-09 14:05:23 +02:00
|
|
|
static inline DOUBLE week_day(DOUBLE time)
|
|
|
|
{
|
2009-06-16 11:41:39 +02:00
|
|
|
DOUBLE ret;
|
|
|
|
|
2009-06-09 14:05:23 +02:00
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-09 14:05:23 +02:00
|
|
|
|
2009-06-16 11:41:39 +02:00
|
|
|
ret = fmod(day(time)+4, 7);
|
|
|
|
if(ret<0) ret += 7;
|
|
|
|
|
|
|
|
return ret;
|
2009-06-09 14:05:23 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:01 +02:00
|
|
|
static inline DOUBLE convert_time(int year, SYSTEMTIME st)
|
|
|
|
{
|
|
|
|
DOUBLE time;
|
|
|
|
int set_week_day;
|
|
|
|
|
|
|
|
if(st.wMonth == 0)
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-22 20:40:01 +02:00
|
|
|
|
|
|
|
if(st.wYear != 0)
|
|
|
|
year = st.wYear;
|
|
|
|
|
|
|
|
time = time_from_year(year);
|
|
|
|
time += (DOUBLE)day_from_month(st.wMonth-1, in_leap_year(time)) * MS_PER_DAY;
|
|
|
|
|
|
|
|
if(st.wYear == 0) {
|
|
|
|
set_week_day = st.wDayOfWeek-week_day(time);
|
|
|
|
if(set_week_day < 0)
|
|
|
|
set_week_day += 7;
|
|
|
|
time += set_week_day * MS_PER_DAY;
|
|
|
|
|
|
|
|
time += (DOUBLE)(st.wDay-1) * 7 * MS_PER_DAY;
|
|
|
|
if(month_from_time(time) != st.wMonth-1)
|
|
|
|
time -= 7 * MS_PER_DAY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
time += st.wDay * MS_PER_DAY;
|
|
|
|
|
|
|
|
time += st.wHour * MS_PER_HOUR;
|
|
|
|
time += st.wMinute * MS_PER_MINUTE;
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 15.9.1.9 */
|
|
|
|
static inline DOUBLE daylight_saving_ta(DOUBLE time, DateInstance *date)
|
|
|
|
{
|
|
|
|
int year = year_from_time(time);
|
|
|
|
DOUBLE standardTime, daylightTime;
|
|
|
|
|
|
|
|
if(isnan(time))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
standardTime = convert_time(year, date->standardDate);
|
|
|
|
daylightTime = convert_time(year, date->daylightDate);
|
|
|
|
|
|
|
|
if(isnan(standardTime) || isnan(daylightTime))
|
|
|
|
return 0;
|
|
|
|
else if(standardTime > daylightTime) {
|
|
|
|
if(daylightTime <= time && time < standardTime)
|
|
|
|
return date->daylightBias;
|
|
|
|
|
|
|
|
return date->standardBias;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(standardTime <= time && time < daylightTime)
|
|
|
|
return date->standardBias;
|
|
|
|
|
|
|
|
return date->daylightBias;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:33 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.9 */
|
|
|
|
static inline DOUBLE local_time(DOUBLE time, DateInstance *date)
|
|
|
|
{
|
|
|
|
return time - (daylight_saving_ta(time, date)+date->bias)*MS_PER_MINUTE;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:01 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.9 */
|
|
|
|
static inline DOUBLE utc(DOUBLE time, DateInstance *date)
|
|
|
|
{
|
|
|
|
time += date->bias * MS_PER_MINUTE;
|
|
|
|
return time + daylight_saving_ta(time, date)*MS_PER_MINUTE;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.10 */
|
2009-06-09 15:39:18 +02:00
|
|
|
static inline DOUBLE hour_from_time(DOUBLE time)
|
|
|
|
{
|
2009-06-16 11:41:39 +02:00
|
|
|
DOUBLE ret;
|
|
|
|
|
2009-06-09 15:39:18 +02:00
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-09 15:39:18 +02:00
|
|
|
|
2009-06-16 11:41:39 +02:00
|
|
|
ret = fmod(floor(time/MS_PER_HOUR), 24);
|
|
|
|
if(ret<0) ret += 24;
|
|
|
|
|
|
|
|
return ret;
|
2009-06-09 15:39:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.10 */
|
2009-06-16 11:41:52 +02:00
|
|
|
static inline DOUBLE min_from_time(DOUBLE time)
|
|
|
|
{
|
|
|
|
DOUBLE ret;
|
|
|
|
|
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-16 11:41:52 +02:00
|
|
|
|
|
|
|
ret = fmod(floor(time/MS_PER_MINUTE), 60);
|
|
|
|
if(ret<0) ret += 60;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.10 */
|
2009-06-16 11:41:58 +02:00
|
|
|
static inline DOUBLE sec_from_time(DOUBLE time)
|
|
|
|
{
|
|
|
|
DOUBLE ret;
|
|
|
|
|
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-16 11:41:58 +02:00
|
|
|
|
|
|
|
ret = fmod(floor(time/1000), 60);
|
|
|
|
if(ret<0) ret += 60;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.10 */
|
2009-06-16 11:42:04 +02:00
|
|
|
static inline DOUBLE ms_from_time(DOUBLE time)
|
|
|
|
{
|
|
|
|
DOUBLE ret;
|
|
|
|
|
|
|
|
if(isnan(time))
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2009-06-16 11:42:04 +02:00
|
|
|
|
|
|
|
ret = fmod(time, 1000);
|
|
|
|
if(ret<0) ret += 1000;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:01 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.11 */
|
|
|
|
static inline DOUBLE make_time(DOUBLE hour, DOUBLE min, DOUBLE sec, DOUBLE ms)
|
|
|
|
{
|
|
|
|
return hour*MS_PER_HOUR + min*MS_PER_MINUTE + sec*1000 + ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 15.9.1.12 */
|
|
|
|
static inline DOUBLE make_day(DOUBLE year, DOUBLE month, DOUBLE day)
|
|
|
|
{
|
|
|
|
DOUBLE time;
|
|
|
|
|
|
|
|
year += floor(month/12);
|
|
|
|
|
|
|
|
month = fmod(month, 12);
|
|
|
|
if(month<0) month += 12;
|
|
|
|
|
|
|
|
time = time_from_year(year);
|
|
|
|
|
|
|
|
day += floor(time / MS_PER_DAY);
|
|
|
|
day += day_from_month(month, in_leap_year(time));
|
|
|
|
|
|
|
|
return day-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 15.9.1.13 */
|
|
|
|
static inline DOUBLE make_date(DOUBLE day, DOUBLE time)
|
|
|
|
{
|
|
|
|
return day*MS_PER_DAY + time;
|
|
|
|
}
|
|
|
|
|
2008-10-13 23:28:00 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.14 */
|
|
|
|
static inline DOUBLE time_clip(DOUBLE time)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2008-10-13 23:28:00 +02:00
|
|
|
if(8.64e15 < time || time < -8.64e15) {
|
2012-05-29 12:53:55 +02:00
|
|
|
return NAN;
|
2008-10-13 23:28:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return floor(time);
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 19:18:49 +01:00
|
|
|
static double date_now(void)
|
|
|
|
{
|
|
|
|
FILETIME ftime;
|
|
|
|
LONGLONG time;
|
|
|
|
|
|
|
|
GetSystemTimeAsFileTime(&ftime);
|
|
|
|
time = ((LONGLONG)ftime.dwHighDateTime << 32) + ftime.dwLowDateTime;
|
|
|
|
|
|
|
|
return time/10000 - TIME_EPOCH;
|
|
|
|
}
|
|
|
|
|
2009-06-28 23:39:15 +02:00
|
|
|
static SYSTEMTIME create_systemtime(DOUBLE time)
|
|
|
|
{
|
|
|
|
SYSTEMTIME st;
|
|
|
|
|
|
|
|
st.wYear = year_from_time(time);
|
|
|
|
st.wMonth = month_from_time(time) + 1;
|
|
|
|
st.wDayOfWeek = week_day(time);
|
|
|
|
st.wDay = date_from_time(time);
|
|
|
|
st.wHour = hour_from_time(time);
|
|
|
|
st.wMinute = min_from_time(time);
|
|
|
|
st.wSecond = sec_from_time(time);
|
|
|
|
st.wMilliseconds = ms_from_time(time);
|
|
|
|
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
static inline HRESULT date_to_string(DOUBLE time, BOOL show_offset, int offset, jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-28 23:39:51 +02:00
|
|
|
static const WCHAR formatW[] = { '%','s',' ','%','s',' ','%','d',' ',
|
|
|
|
'%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
|
|
|
|
'U','T','C','%','c','%','0','2','d','%','0','2','d',' ','%','d','%','s',0 };
|
|
|
|
static const WCHAR formatUTCW[] = { '%','s',' ','%','s',' ','%','d',' ',
|
|
|
|
'%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ',
|
|
|
|
'U','T','C',' ','%','d','%','s',0 };
|
2009-07-06 10:38:14 +02:00
|
|
|
static const WCHAR formatNoOffsetW[] = { '%','s',' ','%','s',' ',
|
|
|
|
'%','d',' ','%','0','2','d',':','%','0','2','d',':',
|
|
|
|
'%','0','2','d',' ','%','d','%','s',0 };
|
2009-06-28 23:39:51 +02:00
|
|
|
static const WCHAR ADW[] = { 0 };
|
|
|
|
static const WCHAR BCW[] = { ' ','B','.','C','.',0 };
|
|
|
|
|
|
|
|
static const DWORD week_ids[] = { LOCALE_SABBREVDAYNAME7, LOCALE_SABBREVDAYNAME1,
|
|
|
|
LOCALE_SABBREVDAYNAME2, LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4,
|
|
|
|
LOCALE_SABBREVDAYNAME5, LOCALE_SABBREVDAYNAME6 };
|
|
|
|
static const DWORD month_ids[] = { LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2,
|
|
|
|
LOCALE_SABBREVMONTHNAME3, LOCALE_SABBREVMONTHNAME4,
|
|
|
|
LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,
|
|
|
|
LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8,
|
|
|
|
LOCALE_SABBREVMONTHNAME9, LOCALE_SABBREVMONTHNAME10,
|
|
|
|
LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
|
|
|
|
|
|
|
|
BOOL formatAD = TRUE;
|
2012-10-11 12:17:37 +02:00
|
|
|
WCHAR week[64], month[64];
|
2016-09-11 18:48:54 +02:00
|
|
|
WCHAR buf[192];
|
2013-03-25 12:28:38 +01:00
|
|
|
jsstr_t *date_jsstr;
|
2016-09-11 18:48:54 +02:00
|
|
|
int year, day;
|
2012-10-11 12:17:37 +02:00
|
|
|
DWORD lcid_en;
|
2009-06-28 23:39:51 +02:00
|
|
|
WCHAR sign = '-';
|
|
|
|
|
2009-07-06 10:38:14 +02:00
|
|
|
if(isnan(time)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_nan());
|
2009-06-28 23:39:51 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2009-06-28 23:39:51 +02:00
|
|
|
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
|
|
|
|
|
2016-09-11 18:48:54 +02:00
|
|
|
week[0] = 0;
|
2018-07-09 20:59:12 +02:00
|
|
|
GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, ARRAY_SIZE(week));
|
2009-06-28 23:39:51 +02:00
|
|
|
|
2016-09-11 18:48:54 +02:00
|
|
|
month[0] = 0;
|
2018-07-09 20:59:12 +02:00
|
|
|
GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, ARRAY_SIZE(month));
|
2009-06-28 23:39:51 +02:00
|
|
|
|
|
|
|
year = year_from_time(time);
|
|
|
|
if(year<0) {
|
|
|
|
formatAD = FALSE;
|
|
|
|
year = -year+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
day = date_from_time(time);
|
|
|
|
|
2016-09-11 18:48:54 +02:00
|
|
|
if(offset < 0) {
|
2009-06-28 23:39:51 +02:00
|
|
|
sign = '+';
|
|
|
|
offset = -offset;
|
|
|
|
}
|
|
|
|
|
2009-07-06 10:38:14 +02:00
|
|
|
if(!show_offset)
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), formatNoOffsetW, week, month, day,
|
2009-07-06 10:38:14 +02:00
|
|
|
(int)hour_from_time(time), (int)min_from_time(time),
|
|
|
|
(int)sec_from_time(time), year, formatAD?ADW:BCW);
|
|
|
|
else if(offset)
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), formatW, week, month, day,
|
2009-06-28 23:39:51 +02:00
|
|
|
(int)hour_from_time(time), (int)min_from_time(time),
|
|
|
|
(int)sec_from_time(time), sign, offset/60, offset%60,
|
|
|
|
year, formatAD?ADW:BCW);
|
|
|
|
else
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), formatUTCW, week, month, day,
|
2009-07-06 10:38:14 +02:00
|
|
|
(int)hour_from_time(time), (int)min_from_time(time),
|
|
|
|
(int)sec_from_time(time), year, formatAD?ADW:BCW);
|
2009-06-28 23:39:51 +02:00
|
|
|
|
2016-09-11 18:48:54 +02:00
|
|
|
date_jsstr = jsstr_alloc(buf);
|
|
|
|
if(!date_jsstr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2013-03-25 12:28:38 +01:00
|
|
|
*r = jsval_string(date_jsstr);
|
2009-06-28 23:39:51 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-07-06 10:38:14 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.2 */
|
2012-09-17 15:16:20 +02:00
|
|
|
static HRESULT dateobj_to_string(DateInstance *date, jsval_t *r)
|
2009-07-06 10:38:14 +02:00
|
|
|
{
|
|
|
|
DOUBLE time;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
time = local_time(date->time, date);
|
|
|
|
offset = date->bias +
|
|
|
|
daylight_saving_ta(time, date);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
return date_to_string(time, TRUE, offset, r);
|
2009-07-06 10:38:14 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
static HRESULT Date_toString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2009-09-23 16:13:44 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-09-23 16:13:44 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-09-23 16:13:44 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
return dateobj_to_string(date, r);
|
2009-09-23 16:13:44 +02:00
|
|
|
}
|
|
|
|
|
2009-06-28 23:39:45 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.1.5 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_toLocaleString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-28 23:39:45 +02:00
|
|
|
SYSTEMTIME st;
|
|
|
|
DateInstance *date;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *date_str;
|
2009-06-28 23:39:45 +02:00
|
|
|
int date_len, time_len;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-28 23:39:45 +02:00
|
|
|
|
|
|
|
if(isnan(date->time)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_nan());
|
2009-06-28 23:39:45 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
st = create_systemtime(local_time(date->time, date));
|
|
|
|
|
|
|
|
if(st.wYear<1601 || st.wYear>9999)
|
2012-09-17 15:16:20 +02:00
|
|
|
return dateobj_to_string(date, r);
|
2009-06-28 23:39:45 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2013-03-25 12:28:38 +01:00
|
|
|
WCHAR *ptr;
|
|
|
|
|
2009-09-23 16:15:55 +02:00
|
|
|
date_len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
|
|
|
|
time_len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
|
2013-03-25 12:28:38 +01:00
|
|
|
|
2016-09-07 10:50:11 +02:00
|
|
|
date_str = jsstr_alloc_buf(date_len+time_len-1, &ptr);
|
2009-06-28 23:39:45 +02:00
|
|
|
if(!date_str)
|
|
|
|
return E_OUTOFMEMORY;
|
2013-03-25 12:28:38 +01:00
|
|
|
|
|
|
|
GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, ptr, date_len);
|
|
|
|
GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr+date_len, time_len);
|
|
|
|
ptr[date_len-1] = ' ';
|
2009-06-28 23:39:45 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_string(date_str);
|
2009-06-28 23:39:45 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2018-04-11 19:36:25 +02:00
|
|
|
static HRESULT Date_toISOString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
|
|
|
jsval_t *r)
|
|
|
|
{
|
|
|
|
DateInstance *date;
|
|
|
|
WCHAR buf[64], *p = buf;
|
|
|
|
double year;
|
|
|
|
|
|
|
|
static const WCHAR short_year_formatW[] = {'%','0','4','d',0};
|
|
|
|
static const WCHAR long_year_formatW[] = {'%','0','6','d',0};
|
|
|
|
static const WCHAR formatW[] = {'-','%','0','2','d','-','%','0','2','d',
|
|
|
|
'T','%','0','2','d',':','%','0','2','d',':','%','0','2','d','.','%','0','3','d','Z',0};
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(!(date = date_this(jsthis)))
|
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
|
|
|
|
|
|
|
year = year_from_time(date->time);
|
|
|
|
if(isnan(year) || year > 999999 || year < -999999) {
|
|
|
|
FIXME("year %lf should throw an exception\n", year);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(year < 0) {
|
|
|
|
*p++ = '-';
|
2019-06-06 09:17:49 +02:00
|
|
|
p += swprintf(p, ARRAY_SIZE(buf) - 1, long_year_formatW, -(int)year);
|
2018-04-11 19:36:25 +02:00
|
|
|
}else if(year > 9999) {
|
|
|
|
*p++ = '+';
|
2019-06-06 09:17:49 +02:00
|
|
|
p += swprintf(p, ARRAY_SIZE(buf) - 1, long_year_formatW, (int)year);
|
2018-04-11 19:36:25 +02:00
|
|
|
}else {
|
2019-06-06 09:17:49 +02:00
|
|
|
p += swprintf(p, ARRAY_SIZE(buf), short_year_formatW, (int)year);
|
2018-04-11 19:36:25 +02:00
|
|
|
}
|
|
|
|
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(p, ARRAY_SIZE(buf) - (p - buf), formatW,
|
|
|
|
(int)month_from_time(date->time) + 1, (int)date_from_time(date->time),
|
2018-04-11 19:36:25 +02:00
|
|
|
(int)hour_from_time(date->time), (int)min_from_time(date->time),
|
|
|
|
(int)sec_from_time(date->time), (int)ms_from_time(date->time));
|
|
|
|
|
|
|
|
if(r) {
|
|
|
|
jsstr_t *ret;
|
|
|
|
if(!(ret = jsstr_alloc(buf)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
*r = jsval_string(ret);
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_valueOf(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-07-06 10:38:31 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-07-06 10:38:31 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-07-06 10:38:31 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
static inline HRESULT create_utc_string(script_ctx_t *ctx, vdisp_t *jsthis, jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-28 23:39:40 +02:00
|
|
|
static const WCHAR formatADW[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ',
|
|
|
|
'%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
|
|
|
|
static const WCHAR formatBCW[] = { '%','s',',',' ','%','d',' ','%','s',' ','%','d',' ','B','.','C','.',' ',
|
|
|
|
'%','0','2','d',':','%','0','2','d',':','%','0','2','d',' ','U','T','C',0 };
|
|
|
|
|
|
|
|
static const DWORD week_ids[] = { LOCALE_SABBREVDAYNAME7, LOCALE_SABBREVDAYNAME1,
|
|
|
|
LOCALE_SABBREVDAYNAME2, LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4,
|
|
|
|
LOCALE_SABBREVDAYNAME5, LOCALE_SABBREVDAYNAME6 };
|
|
|
|
static const DWORD month_ids[] = { LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2,
|
|
|
|
LOCALE_SABBREVMONTHNAME3, LOCALE_SABBREVMONTHNAME4,
|
|
|
|
LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,
|
|
|
|
LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8,
|
|
|
|
LOCALE_SABBREVMONTHNAME9, LOCALE_SABBREVMONTHNAME10,
|
|
|
|
LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
|
|
|
|
|
|
|
|
BOOL formatAD = TRUE;
|
2012-10-11 12:17:37 +02:00
|
|
|
WCHAR week[64], month[64];
|
2016-09-11 18:50:26 +02:00
|
|
|
WCHAR buf[192];
|
2009-06-28 23:39:40 +02:00
|
|
|
DateInstance *date;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *date_str;
|
2016-09-11 18:50:26 +02:00
|
|
|
int year, day;
|
2012-10-11 12:17:37 +02:00
|
|
|
DWORD lcid_en;
|
2009-06-28 23:39:40 +02:00
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-28 23:39:40 +02:00
|
|
|
|
|
|
|
if(isnan(date->time)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_nan());
|
2009-06-28 23:39:40 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2009-06-28 23:39:40 +02:00
|
|
|
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
|
|
|
|
|
2016-09-11 18:50:26 +02:00
|
|
|
week[0] = 0;
|
2018-07-09 20:59:12 +02:00
|
|
|
GetLocaleInfoW(lcid_en, week_ids[(int)week_day(date->time)], week, ARRAY_SIZE(week));
|
2009-06-28 23:39:40 +02:00
|
|
|
|
2016-09-11 18:50:26 +02:00
|
|
|
month[0] = 0;
|
2018-07-09 20:59:12 +02:00
|
|
|
GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(date->time)], month, ARRAY_SIZE(month));
|
2009-06-28 23:39:40 +02:00
|
|
|
|
|
|
|
year = year_from_time(date->time);
|
|
|
|
if(year<0) {
|
|
|
|
formatAD = FALSE;
|
|
|
|
year = -year+1;
|
|
|
|
}
|
|
|
|
|
2009-07-03 02:45:32 +02:00
|
|
|
day = date_from_time(date->time);
|
2012-10-12 11:48:18 +02:00
|
|
|
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), formatAD ? formatADW : formatBCW, week, day, month, year,
|
2009-06-28 23:39:40 +02:00
|
|
|
(int)hour_from_time(date->time), (int)min_from_time(date->time),
|
|
|
|
(int)sec_from_time(date->time));
|
|
|
|
|
2016-09-11 18:50:26 +02:00
|
|
|
date_str = jsstr_alloc(buf);
|
|
|
|
if(!date_str)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_string(date_str);
|
2009-06-28 23:39:40 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-10-07 22:11:38 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.42 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_toUTCString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2009-10-07 22:11:38 +02:00
|
|
|
{
|
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return create_utc_string(ctx, jsthis, r);
|
2009-10-07 22:11:38 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_toGMTString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2009-10-06 13:11:25 +02:00
|
|
|
{
|
2009-10-07 22:11:38 +02:00
|
|
|
TRACE("\n");
|
2012-09-18 19:01:49 +02:00
|
|
|
return create_utc_string(ctx, jsthis, r);
|
2009-10-06 13:11:25 +02:00
|
|
|
}
|
|
|
|
|
2009-06-28 23:39:36 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.3 */
|
2012-09-17 15:16:20 +02:00
|
|
|
static HRESULT dateobj_to_date_string(DateInstance *date, jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-28 23:39:36 +02:00
|
|
|
static const WCHAR formatADW[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',0 };
|
|
|
|
static const WCHAR formatBCW[] = { '%','s',' ','%','s',' ','%','d',' ','%','d',' ','B','.','C','.',0 };
|
|
|
|
|
|
|
|
static const DWORD week_ids[] = { LOCALE_SABBREVDAYNAME7, LOCALE_SABBREVDAYNAME1,
|
|
|
|
LOCALE_SABBREVDAYNAME2, LOCALE_SABBREVDAYNAME3, LOCALE_SABBREVDAYNAME4,
|
|
|
|
LOCALE_SABBREVDAYNAME5, LOCALE_SABBREVDAYNAME6 };
|
|
|
|
static const DWORD month_ids[] = { LOCALE_SABBREVMONTHNAME1, LOCALE_SABBREVMONTHNAME2,
|
|
|
|
LOCALE_SABBREVMONTHNAME3, LOCALE_SABBREVMONTHNAME4,
|
|
|
|
LOCALE_SABBREVMONTHNAME5, LOCALE_SABBREVMONTHNAME6,
|
|
|
|
LOCALE_SABBREVMONTHNAME7, LOCALE_SABBREVMONTHNAME8,
|
|
|
|
LOCALE_SABBREVMONTHNAME9, LOCALE_SABBREVMONTHNAME10,
|
|
|
|
LOCALE_SABBREVMONTHNAME11, LOCALE_SABBREVMONTHNAME12 };
|
|
|
|
|
|
|
|
BOOL formatAD = TRUE;
|
2012-10-11 12:17:37 +02:00
|
|
|
WCHAR week[64], month[64];
|
2016-09-11 18:47:57 +02:00
|
|
|
WCHAR buf[192];
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *date_str;
|
2009-06-28 23:39:36 +02:00
|
|
|
DOUBLE time;
|
2016-09-11 18:47:57 +02:00
|
|
|
int year, day;
|
2012-10-11 12:17:37 +02:00
|
|
|
DWORD lcid_en;
|
2009-06-28 23:39:36 +02:00
|
|
|
|
|
|
|
if(isnan(date->time)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_nan());
|
2009-06-28 23:39:36 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
time = local_time(date->time, date);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2009-06-28 23:39:36 +02:00
|
|
|
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
|
|
|
|
|
2016-09-11 18:47:57 +02:00
|
|
|
week[0] = 0;
|
2018-07-09 20:59:12 +02:00
|
|
|
GetLocaleInfoW(lcid_en, week_ids[(int)week_day(time)], week, ARRAY_SIZE(week));
|
2009-06-28 23:39:36 +02:00
|
|
|
|
2016-09-11 18:47:57 +02:00
|
|
|
month[0] = 0;
|
2018-07-09 20:59:12 +02:00
|
|
|
GetLocaleInfoW(lcid_en, month_ids[(int)month_from_time(time)], month, ARRAY_SIZE(month));
|
2009-06-28 23:39:36 +02:00
|
|
|
|
|
|
|
year = year_from_time(time);
|
|
|
|
if(year<0) {
|
|
|
|
formatAD = FALSE;
|
|
|
|
year = -year+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
day = date_from_time(time);
|
|
|
|
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), formatAD ? formatADW : formatBCW, week, month, day, year);
|
2016-09-11 18:47:57 +02:00
|
|
|
|
|
|
|
date_str = jsstr_alloc(buf);
|
2016-09-07 10:50:11 +02:00
|
|
|
if(!date_str)
|
2009-06-28 23:39:36 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_string(date_str);
|
2009-06-28 23:39:36 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_toDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2009-09-23 16:13:44 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-09-23 16:13:44 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
return dateobj_to_date_string(date, r);
|
2009-09-23 16:13:44 +02:00
|
|
|
}
|
|
|
|
|
2009-06-28 23:39:32 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.4 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_toTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-28 23:39:32 +02:00
|
|
|
static const WCHAR formatW[] = { '%','0','2','d',':','%','0','2','d',':','%','0','2','d',
|
|
|
|
' ','U','T','C','%','c','%','0','2','d','%','0','2','d',0 };
|
|
|
|
static const WCHAR formatUTCW[] = { '%','0','2','d',':','%','0','2','d',
|
|
|
|
':','%','0','2','d',' ','U','T','C',0 };
|
|
|
|
DateInstance *date;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *date_str;
|
2016-09-08 23:54:54 +02:00
|
|
|
WCHAR buf[32];
|
2009-06-28 23:39:32 +02:00
|
|
|
DOUBLE time;
|
|
|
|
WCHAR sign;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-28 23:39:32 +02:00
|
|
|
|
|
|
|
if(isnan(date->time)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_nan());
|
|
|
|
return S_OK;
|
2009-06-28 23:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
time = local_time(date->time, date);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2009-06-28 23:39:32 +02:00
|
|
|
offset = date->bias +
|
|
|
|
daylight_saving_ta(time, date);
|
|
|
|
|
|
|
|
if(offset < 0) {
|
|
|
|
sign = '+';
|
|
|
|
offset = -offset;
|
|
|
|
}
|
|
|
|
else sign = '-';
|
|
|
|
|
|
|
|
if(offset)
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), formatW, (int)hour_from_time(time),
|
2009-06-28 23:39:32 +02:00
|
|
|
(int)min_from_time(time), (int)sec_from_time(time),
|
|
|
|
sign, offset/60, offset%60);
|
|
|
|
else
|
2019-06-06 09:17:49 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), formatUTCW, (int)hour_from_time(time),
|
2009-06-28 23:39:32 +02:00
|
|
|
(int)min_from_time(time), (int)sec_from_time(time));
|
|
|
|
|
2016-09-08 23:54:54 +02:00
|
|
|
date_str = jsstr_alloc(buf);
|
|
|
|
if(!date_str)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_string(date_str);
|
2009-06-28 23:39:32 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-28 23:39:15 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.6 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_toLocaleDateString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-28 23:39:15 +02:00
|
|
|
SYSTEMTIME st;
|
|
|
|
DateInstance *date;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *date_str;
|
2009-06-28 23:39:15 +02:00
|
|
|
int len;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-28 23:39:15 +02:00
|
|
|
|
|
|
|
if(isnan(date->time)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_nan());
|
2009-06-28 23:39:15 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
st = create_systemtime(local_time(date->time, date));
|
|
|
|
|
|
|
|
if(st.wYear<1601 || st.wYear>9999)
|
2012-09-17 15:16:20 +02:00
|
|
|
return dateobj_to_date_string(date, r);
|
2009-06-28 23:39:15 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2013-03-25 12:28:38 +01:00
|
|
|
WCHAR *ptr;
|
|
|
|
|
2009-09-23 16:15:55 +02:00
|
|
|
len = GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, NULL, 0);
|
2016-09-07 19:04:48 +02:00
|
|
|
date_str = jsstr_alloc_buf(len-1, &ptr);
|
2016-09-07 10:50:11 +02:00
|
|
|
if(!date_str)
|
2009-06-28 23:39:15 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2013-03-25 12:28:38 +01:00
|
|
|
GetDateFormatW(ctx->lcid, DATE_LONGDATE, &st, NULL, ptr, len);
|
2009-06-28 23:39:15 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_string(date_str);
|
2009-06-28 23:39:15 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-28 23:39:27 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.7 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_toLocaleTimeString(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-28 23:39:27 +02:00
|
|
|
SYSTEMTIME st;
|
|
|
|
DateInstance *date;
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *date_str;
|
2009-06-28 23:39:27 +02:00
|
|
|
int len;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-28 23:39:27 +02:00
|
|
|
|
|
|
|
if(isnan(date->time)) {
|
2012-10-11 12:16:01 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_string(jsstr_nan());
|
2009-06-28 23:39:27 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
st = create_systemtime(local_time(date->time, date));
|
|
|
|
|
|
|
|
if(st.wYear<1601 || st.wYear>9999)
|
2012-09-18 19:01:49 +02:00
|
|
|
return Date_toTimeString(ctx, jsthis, flags, argc, argv, r);
|
2009-06-28 23:39:27 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2013-03-25 12:28:38 +01:00
|
|
|
WCHAR *ptr;
|
|
|
|
|
2009-09-23 16:15:55 +02:00
|
|
|
len = GetTimeFormatW(ctx->lcid, 0, &st, NULL, NULL, 0);
|
2016-09-07 19:04:48 +02:00
|
|
|
date_str = jsstr_alloc_buf(len-1, &ptr);
|
2016-09-07 10:50:11 +02:00
|
|
|
if(!date_str)
|
2009-06-28 23:39:27 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2013-03-25 12:28:38 +01:00
|
|
|
GetTimeFormatW(ctx->lcid, 0, &st, NULL, ptr, len);
|
2009-06-28 23:39:27 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_string(date_str);
|
2009-06-28 23:39:27 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2008-10-13 23:28:09 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.9 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2008-10-13 23:28:09 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2008-10-13 23:28:09 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2008-10-13 23:28:09 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.10 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:01:01 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:01:01 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r) {
|
2009-06-22 20:40:33 +02:00
|
|
|
DOUBLE time = local_time(date->time, date);
|
2009-06-09 14:01:01 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_number(year_from_time(time));
|
2009-06-09 14:01:01 +02:00
|
|
|
}
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.11 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:01:01 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:01:01 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(year_from_time(date->time));
|
2009-06-09 14:01:01 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.12 */
|
2012-09-18 19:01:49 +02:00
|
|
|
static HRESULT Date_getMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:02:42 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:02:42 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(month_from_time(local_time(date->time, date)));
|
2009-06-09 14:02:42 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.13 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:02:42 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:02:42 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(month_from_time(date->time));
|
2009-06-09 14:02:42 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.14 */
|
2012-09-18 19:01:49 +02:00
|
|
|
static HRESULT Date_getDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:04:09 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:04:09 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date_from_time(local_time(date->time, date)));
|
2009-06-09 14:04:09 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.15 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:04:09 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:04:09 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date_from_time(date->time));
|
2009-06-09 14:04:09 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.16 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getDay(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:05:23 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:05:23 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(week_day(local_time(date->time, date)));
|
2009-06-09 14:05:23 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.17 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCDay(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 14:05:23 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 14:05:23 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(week_day(date->time));
|
2009-06-09 14:05:23 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.18 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 15:39:18 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 15:39:18 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(hour_from_time(local_time(date->time, date)));
|
2009-06-09 15:39:18 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.19 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-09 15:39:18 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-09 15:39:18 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(hour_from_time(date->time));
|
2009-06-09 15:39:18 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.20 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-16 11:41:52 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:41:52 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(min_from_time(local_time(date->time, date)));
|
2009-06-16 11:41:52 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.21 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-16 11:41:52 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:41:52 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(min_from_time(date->time));
|
2009-06-16 11:41:52 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.22 */
|
2012-09-18 19:01:49 +02:00
|
|
|
static HRESULT Date_getSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-16 11:41:58 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:41:58 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(sec_from_time(local_time(date->time, date)));
|
2009-06-16 11:41:58 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.23 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-16 11:41:58 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:41:58 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(sec_from_time(date->time));
|
2009-06-16 11:41:58 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.24 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-16 11:42:04 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:42:04 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(ms_from_time(local_time(date->time, date)));
|
2009-06-16 11:42:04 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.25 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-16 11:42:04 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:42:04 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(ms_from_time(date->time));
|
2009-06-16 11:42:04 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.26 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getTimezoneOffset(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
|
|
|
|
2009-06-22 20:40:33 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:40:33 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(floor((date->time-local_time(date->time, date))/MS_PER_MINUTE));
|
2009-06-22 20:40:33 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.27 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setTime(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2009-06-04 22:37:08 +02:00
|
|
|
HRESULT hres;
|
|
|
|
DateInstance *date;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-04 22:37:08 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-04 22:37:08 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &n);
|
2009-06-04 22:37:08 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
date->time = time_clip(n);
|
2009-06-04 22:37:08 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-04 22:37:08 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.28 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-16 11:42:10 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double n, t;
|
|
|
|
HRESULT hres;
|
2009-06-16 11:42:10 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:42:10 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-16 11:42:10 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &n);
|
2009-06-16 11:42:10 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2009-06-22 20:41:01 +02:00
|
|
|
t = local_time(date->time, date);
|
|
|
|
t = make_date(day(t), make_time(hour_from_time(t), min_from_time(t),
|
2012-03-27 11:28:51 +02:00
|
|
|
sec_from_time(t), n));
|
2009-06-22 20:41:01 +02:00
|
|
|
date->time = time_clip(utc(t, date));
|
2009-06-16 11:42:10 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-16 11:42:10 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.29 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setUTCMilliseconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:41:01 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double n, t;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:41:01 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:41:01 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:41:01 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &n);
|
2009-06-22 20:41:01 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
t = date->time;
|
|
|
|
t = make_date(day(t), make_time(hour_from_time(t), min_from_time(t),
|
2012-03-27 11:28:51 +02:00
|
|
|
sec_from_time(t), n));
|
2009-06-22 20:41:01 +02:00
|
|
|
date->time = time_clip(t);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:41:01 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.30 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-16 11:42:15 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, sec, ms;
|
|
|
|
HRESULT hres;
|
2009-06-16 11:42:15 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:42:15 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-16 11:42:15 +02:00
|
|
|
|
2009-06-22 20:41:11 +02:00
|
|
|
t = local_time(date->time, date);
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &sec);
|
2009-06-16 11:42:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &ms);
|
2009-06-22 20:41:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ms = ms_from_time(t);
|
2009-06-22 20:41:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(day(t), make_time(hour_from_time(t),
|
|
|
|
min_from_time(t), sec, ms));
|
|
|
|
date->time = time_clip(utc(t, date));
|
2009-06-16 11:42:15 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-16 11:42:15 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.31 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setUTCSeconds(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:41:11 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, sec, ms;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:41:11 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:41:11 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:41:11 +02:00
|
|
|
|
|
|
|
t = date->time;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &sec);
|
2009-06-22 20:41:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &ms);
|
2009-06-22 20:41:11 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ms = ms_from_time(t);
|
2009-06-22 20:41:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(day(t), make_time(hour_from_time(t),
|
|
|
|
min_from_time(t), sec, ms));
|
|
|
|
date->time = time_clip(t);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:41:11 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.33 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-16 11:42:20 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, min, sec, ms;
|
|
|
|
HRESULT hres;
|
2009-06-16 11:42:20 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:42:20 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-16 11:42:20 +02:00
|
|
|
|
2009-06-22 20:41:28 +02:00
|
|
|
t = local_time(date->time, date);
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &min);
|
2009-06-16 11:42:20 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &sec);
|
2009-06-22 20:41:28 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
sec = sec_from_time(t);
|
2009-06-22 20:41:28 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 2) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[2], &ms);
|
2009-06-22 20:41:28 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ms = ms_from_time(t);
|
2009-06-22 20:41:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(day(t), make_time(hour_from_time(t),
|
|
|
|
min, sec, ms));
|
|
|
|
date->time = time_clip(utc(t, date));
|
2009-06-16 11:42:20 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-16 11:42:20 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.34 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setUTCMinutes(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:41:28 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, min, sec, ms;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:41:28 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:41:28 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:41:28 +02:00
|
|
|
|
|
|
|
t = date->time;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &min);
|
2009-06-22 20:41:28 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &sec);
|
2009-06-22 20:41:28 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
sec = sec_from_time(t);
|
2009-06-22 20:41:28 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 2) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[2], &ms);
|
2009-06-22 20:41:28 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ms = ms_from_time(t);
|
2009-06-22 20:41:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(day(t), make_time(hour_from_time(t),
|
|
|
|
min, sec, ms));
|
|
|
|
date->time = time_clip(t);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:41:28 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.35 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-16 11:42:27 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, hour, min, sec, ms;
|
|
|
|
HRESULT hres;
|
2009-06-16 11:42:27 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:42:27 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-16 11:42:27 +02:00
|
|
|
|
2009-06-22 20:41:40 +02:00
|
|
|
t = local_time(date->time, date);
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &hour);
|
2009-06-16 11:42:27 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &min);
|
2009-06-22 20:41:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
min = min_from_time(t);
|
2009-06-22 20:41:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 2) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[2], &sec);
|
2009-06-22 20:41:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
sec = sec_from_time(t);
|
2009-06-22 20:41:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 3) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[3], &ms);
|
2009-06-22 20:41:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ms = ms_from_time(t);
|
2009-06-22 20:41:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(day(t), make_time(hour, min, sec, ms));
|
|
|
|
date->time = time_clip(utc(t, date));
|
2009-06-16 11:42:27 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-16 11:42:27 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.36 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setUTCHours(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-09-23 16:18:39 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, hour, min, sec, ms;
|
2009-06-16 11:42:27 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-16 11:42:27 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-16 11:42:27 +02:00
|
|
|
|
2009-06-22 20:41:40 +02:00
|
|
|
t = date->time;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &hour);
|
2009-06-16 11:42:27 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &min);
|
2009-06-22 20:41:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
min = min_from_time(t);
|
2009-06-22 20:41:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 2) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[2], &sec);
|
2009-06-22 20:41:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
sec = sec_from_time(t);
|
2009-06-22 20:41:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 3) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[3], &ms);
|
2009-06-22 20:41:40 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ms = ms_from_time(t);
|
2009-06-22 20:41:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(day(t), make_time(hour, min, sec, ms));
|
|
|
|
date->time = time_clip(t);
|
2009-06-16 11:42:27 +02:00
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-16 11:42:27 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.36 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:41:50 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, n;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:41:50 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:41:50 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:41:50 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &n);
|
2009-06-22 20:41:50 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
t = local_time(date->time, date);
|
2012-03-27 11:28:51 +02:00
|
|
|
t = make_date(make_day(year_from_time(t), month_from_time(t), n), time_within_day(t));
|
2009-06-22 20:41:50 +02:00
|
|
|
date->time = time_clip(utc(t, date));
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:41:50 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:46 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.37 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setUTCDate(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:41:50 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, n;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:41:50 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:41:50 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:41:50 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &n);
|
2009-06-22 20:41:50 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
t = date->time;
|
2012-03-27 11:28:51 +02:00
|
|
|
t = make_date(make_day(year_from_time(t), month_from_time(t), n), time_within_day(t));
|
2009-06-22 20:41:50 +02:00
|
|
|
date->time = time_clip(t);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:41:50 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:42:00 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.38 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:42:00 +02:00
|
|
|
DateInstance *date;
|
|
|
|
DOUBLE t, month, ddate;
|
2012-03-27 11:28:51 +02:00
|
|
|
HRESULT hres;
|
2009-06-22 20:42:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:42:00 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:42:00 +02:00
|
|
|
|
|
|
|
t = local_time(date->time, date);
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &month);
|
2009-06-22 20:42:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &ddate);
|
2009-06-22 20:42:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ddate = date_from_time(t);
|
2009-06-22 20:42:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(make_day(year_from_time(t), month, ddate),
|
|
|
|
time_within_day(t));
|
|
|
|
date->time = time_clip(utc(t, date));
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:42:00 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:42:00 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.39 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setUTCMonth(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:42:00 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, month, ddate;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:42:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:42:00 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:42:00 +02:00
|
|
|
|
|
|
|
t = date->time;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &month);
|
2009-06-22 20:42:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &ddate);
|
2009-06-22 20:42:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ddate = date_from_time(t);
|
2009-06-22 20:42:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(make_day(year_from_time(t), month, ddate),
|
|
|
|
time_within_day(t));
|
|
|
|
date->time = time_clip(t);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:42:00 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:42:15 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.40 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:42:15 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, year, month, ddate;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:42:15 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:42:15 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:42:15 +02:00
|
|
|
|
|
|
|
t = local_time(date->time, date);
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &year);
|
2009-06-22 20:42:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &month);
|
2009-06-22 20:42:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
month = month_from_time(t);
|
2009-06-22 20:42:15 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 2) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[2], &ddate);
|
2009-06-22 20:42:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ddate = date_from_time(t);
|
2009-06-22 20:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(make_day(year, month, ddate), time_within_day(t));
|
|
|
|
date->time = time_clip(utc(t, date));
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:42:15 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-06-22 20:42:15 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.5.41 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setUTCFullYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-06-22 20:42:15 +02:00
|
|
|
DateInstance *date;
|
2012-03-27 11:28:51 +02:00
|
|
|
double t, year, month, ddate;
|
|
|
|
HRESULT hres;
|
2009-06-22 20:42:15 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-06-22 20:42:15 +02:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2009-06-22 20:42:15 +02:00
|
|
|
|
|
|
|
t = date->time;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &year);
|
2009-06-22 20:42:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &month);
|
2009-06-22 20:42:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
month = month_from_time(t);
|
2009-06-22 20:42:15 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc > 2) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[2], &ddate);
|
2009-06-22 20:42:15 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
ddate = date_from_time(t);
|
2009-06-22 20:42:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t = make_date(make_day(year, month, ddate), time_within_day(t));
|
|
|
|
date->time = time_clip(t);
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2009-06-22 20:42:15 +02:00
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-07-14 01:37:11 +02:00
|
|
|
/* ECMA-262 3rd Edition B2.4 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_getYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2009-07-14 01:37:11 +02:00
|
|
|
{
|
|
|
|
DateInstance *date;
|
|
|
|
DOUBLE t, year;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-09-23 16:18:39 +02:00
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2009-07-14 01:37:11 +02:00
|
|
|
|
|
|
|
t = local_time(date->time, date);
|
|
|
|
if(isnan(t)) {
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(NAN);
|
2009-07-14 01:37:11 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
year = year_from_time(t);
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number((1900<=year && year<2000)?year-1900:year);
|
2009-07-14 01:37:11 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-06 21:29:19 +01:00
|
|
|
/* ECMA-262 3rd Edition B2.5 */
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2010-11-06 21:29:19 +01:00
|
|
|
{
|
2010-12-20 12:21:42 +01:00
|
|
|
DateInstance *date;
|
|
|
|
DOUBLE t, year;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(!(date = date_this(jsthis)))
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_DATE_EXPECTED, NULL);
|
2010-12-20 12:21:42 +01:00
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc)
|
2012-09-18 19:01:49 +02:00
|
|
|
return throw_type_error(ctx, JS_E_MISSING_ARG, NULL);
|
2010-12-20 12:21:42 +01:00
|
|
|
|
|
|
|
t = local_time(date->time, date);
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &year);
|
2010-12-20 12:21:42 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(isnan(year)) {
|
|
|
|
date->time = year;
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(NAN);
|
2010-12-20 12:21:42 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
year = year >= 0.0 ? floor(year) : -floor(-year);
|
|
|
|
if(-1.0 < year && year < 100.0)
|
|
|
|
year += 1900.0;
|
|
|
|
|
|
|
|
date->time = time_clip(utc(make_date(make_day(year, month_from_time(t), date_from_time(t)), time_within_day(t)), date));
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(date->time);
|
2010-12-20 12:21:42 +01:00
|
|
|
return S_OK;
|
2010-11-06 21:29:19 +01:00
|
|
|
}
|
|
|
|
|
2015-02-06 12:09:40 +01:00
|
|
|
static HRESULT Date_get_value(script_ctx_t *ctx, jsdisp_t *jsthis, jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2009-07-22 13:02:30 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2015-02-06 12:09:40 +01:00
|
|
|
return dateobj_to_string(date_from_jsdisp(jsthis), r);
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const builtin_prop_t Date_props[] = {
|
|
|
|
{getDateW, Date_getDate, PROPF_METHOD},
|
|
|
|
{getDayW, Date_getDay, PROPF_METHOD},
|
|
|
|
{getFullYearW, Date_getFullYear, PROPF_METHOD},
|
|
|
|
{getHoursW, Date_getHours, PROPF_METHOD},
|
2009-06-16 11:42:04 +02:00
|
|
|
{getMillisecondsW, Date_getMilliseconds, PROPF_METHOD},
|
2008-09-30 17:48:18 +02:00
|
|
|
{getMinutesW, Date_getMinutes, PROPF_METHOD},
|
|
|
|
{getMonthW, Date_getMonth, PROPF_METHOD},
|
|
|
|
{getSecondsW, Date_getSeconds, PROPF_METHOD},
|
|
|
|
{getTimeW, Date_getTime, PROPF_METHOD},
|
|
|
|
{getTimezoneOffsetW, Date_getTimezoneOffset, PROPF_METHOD},
|
|
|
|
{getUTCDateW, Date_getUTCDate, PROPF_METHOD},
|
|
|
|
{getUTCDayW, Date_getUTCDay, PROPF_METHOD},
|
|
|
|
{getUTCFullYearW, Date_getUTCFullYear, PROPF_METHOD},
|
|
|
|
{getUTCHoursW, Date_getUTCHours, PROPF_METHOD},
|
2009-06-16 11:42:04 +02:00
|
|
|
{getUTCMillisecondsW, Date_getUTCMilliseconds, PROPF_METHOD},
|
2008-09-30 17:48:18 +02:00
|
|
|
{getUTCMinutesW, Date_getUTCMinutes, PROPF_METHOD},
|
|
|
|
{getUTCMonthW, Date_getUTCMonth, PROPF_METHOD},
|
|
|
|
{getUTCSecondsW, Date_getUTCSeconds, PROPF_METHOD},
|
2009-07-14 01:37:11 +02:00
|
|
|
{getYearW, Date_getYear, PROPF_METHOD},
|
2009-08-17 12:12:49 +02:00
|
|
|
{setDateW, Date_setDate, PROPF_METHOD|1},
|
|
|
|
{setFullYearW, Date_setFullYear, PROPF_METHOD|3},
|
|
|
|
{setHoursW, Date_setHours, PROPF_METHOD|4},
|
|
|
|
{setMillisecondsW, Date_setMilliseconds, PROPF_METHOD|1},
|
|
|
|
{setMinutesW, Date_setMinutes, PROPF_METHOD|3},
|
|
|
|
{setMonthW, Date_setMonth, PROPF_METHOD|2},
|
|
|
|
{setSecondsW, Date_setSeconds, PROPF_METHOD|2},
|
|
|
|
{setTimeW, Date_setTime, PROPF_METHOD|1},
|
|
|
|
{setUTCDateW, Date_setUTCDate, PROPF_METHOD|1},
|
|
|
|
{setUTCFullYearW, Date_setUTCFullYear, PROPF_METHOD|3},
|
|
|
|
{setUTCHoursW, Date_setUTCHours, PROPF_METHOD|4},
|
|
|
|
{setUTCMillisecondsW, Date_setUTCMilliseconds, PROPF_METHOD|1},
|
|
|
|
{setUTCMinutesW, Date_setUTCMinutes, PROPF_METHOD|3},
|
|
|
|
{setUTCMonthW, Date_setUTCMonth, PROPF_METHOD|2},
|
|
|
|
{setUTCSecondsW, Date_setUTCSeconds, PROPF_METHOD|2},
|
2010-11-06 21:29:19 +01:00
|
|
|
{setYearW, Date_setYear, PROPF_METHOD|1},
|
2008-09-30 17:48:18 +02:00
|
|
|
{toDateStringW, Date_toDateString, PROPF_METHOD},
|
2009-10-06 13:11:25 +02:00
|
|
|
{toGMTStringW, Date_toGMTString, PROPF_METHOD},
|
2018-04-11 19:36:25 +02:00
|
|
|
{toISOStringW, Date_toISOString, PROPF_METHOD|PROPF_ES5},
|
2008-09-30 17:48:18 +02:00
|
|
|
{toLocaleDateStringW, Date_toLocaleDateString, PROPF_METHOD},
|
|
|
|
{toLocaleStringW, Date_toLocaleString, PROPF_METHOD},
|
|
|
|
{toLocaleTimeStringW, Date_toLocaleTimeString, PROPF_METHOD},
|
|
|
|
{toStringW, Date_toString, PROPF_METHOD},
|
|
|
|
{toTimeStringW, Date_toTimeString, PROPF_METHOD},
|
|
|
|
{toUTCStringW, Date_toUTCString, PROPF_METHOD},
|
|
|
|
{valueOfW, Date_valueOf, PROPF_METHOD},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t Date_info = {
|
|
|
|
JSCLASS_DATE,
|
2015-02-05 14:49:01 +01:00
|
|
|
{NULL, NULL,0, Date_get_value},
|
2018-07-09 20:59:12 +02:00
|
|
|
ARRAY_SIZE(Date_props),
|
2008-09-30 17:48:18 +02:00
|
|
|
Date_props,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-07-24 13:17:06 +02:00
|
|
|
static const builtin_info_t DateInst_info = {
|
|
|
|
JSCLASS_DATE,
|
2015-02-05 14:49:01 +01:00
|
|
|
{NULL, NULL,0, Date_get_value},
|
2012-07-24 13:17:06 +02:00
|
|
|
0, NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
static HRESULT create_date(script_ctx_t *ctx, jsdisp_t *object_prototype, DOUBLE time, jsdisp_t **ret)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
|
|
|
DateInstance *date;
|
|
|
|
HRESULT hres;
|
2009-06-04 22:36:27 +02:00
|
|
|
TIME_ZONE_INFORMATION tzi;
|
|
|
|
|
2009-07-03 02:45:32 +02:00
|
|
|
GetTimeZoneInformation(&tzi);
|
2008-09-30 17:48:18 +02:00
|
|
|
|
|
|
|
date = heap_alloc_zero(sizeof(DateInstance));
|
|
|
|
if(!date)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2009-08-14 11:53:57 +02:00
|
|
|
if(object_prototype)
|
|
|
|
hres = init_dispex(&date->dispex, ctx, &Date_info, object_prototype);
|
2008-09-30 17:48:18 +02:00
|
|
|
else
|
2012-07-24 13:17:06 +02:00
|
|
|
hres = init_dispex_from_constr(&date->dispex, ctx, &DateInst_info, ctx->date_constr);
|
2008-09-30 17:48:18 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(date);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2008-10-13 23:28:00 +02:00
|
|
|
date->time = time;
|
2009-06-04 22:36:27 +02:00
|
|
|
date->bias = tzi.Bias;
|
2009-06-22 20:40:01 +02:00
|
|
|
date->standardDate = tzi.StandardDate;
|
|
|
|
date->standardBias = tzi.StandardBias;
|
|
|
|
date->daylightDate = tzi.DaylightDate;
|
|
|
|
date->daylightBias = tzi.DaylightBias;
|
2008-10-13 23:28:00 +02:00
|
|
|
|
2008-09-30 17:48:18 +02:00
|
|
|
*ret = &date->dispex;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
static inline HRESULT date_parse(jsstr_t *input_str, double *ret) {
|
2009-07-06 11:00:22 +02:00
|
|
|
static const DWORD string_ids[] = { LOCALE_SMONTHNAME12, LOCALE_SMONTHNAME11,
|
|
|
|
LOCALE_SMONTHNAME10, LOCALE_SMONTHNAME9, LOCALE_SMONTHNAME8,
|
|
|
|
LOCALE_SMONTHNAME7, LOCALE_SMONTHNAME6, LOCALE_SMONTHNAME5,
|
|
|
|
LOCALE_SMONTHNAME4, LOCALE_SMONTHNAME3, LOCALE_SMONTHNAME2,
|
|
|
|
LOCALE_SMONTHNAME1, LOCALE_SDAYNAME7, LOCALE_SDAYNAME1,
|
|
|
|
LOCALE_SDAYNAME2, LOCALE_SDAYNAME3, LOCALE_SDAYNAME4,
|
|
|
|
LOCALE_SDAYNAME5, LOCALE_SDAYNAME6 };
|
2018-07-09 20:59:12 +02:00
|
|
|
WCHAR *strings[ARRAY_SIZE(string_ids)];
|
2012-10-11 12:17:37 +02:00
|
|
|
WCHAR *parse;
|
2009-07-06 11:00:22 +02:00
|
|
|
int input_len, parse_len = 0, nest_level = 0, i, size;
|
|
|
|
int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
|
|
|
|
int ms = 0, offset = 0, hour_adjust = 0;
|
|
|
|
BOOL set_year = FALSE, set_month = FALSE, set_day = FALSE, set_hour = FALSE;
|
|
|
|
BOOL set_offset = FALSE, set_era = FALSE, ad = TRUE, set_am = FALSE, am = TRUE;
|
|
|
|
BOOL set_hour_adjust = TRUE;
|
|
|
|
TIME_ZONE_INFORMATION tzi;
|
2012-10-11 12:16:01 +02:00
|
|
|
const WCHAR *input;
|
2009-07-06 11:00:22 +02:00
|
|
|
DateInstance di;
|
|
|
|
DWORD lcid_en;
|
|
|
|
|
2012-10-11 12:16:01 +02:00
|
|
|
input_len = jsstr_length(input_str);
|
2013-03-26 10:36:58 +01:00
|
|
|
input = jsstr_flatten(input_str);
|
|
|
|
if(!input)
|
|
|
|
return E_OUTOFMEMORY;
|
2012-10-11 12:16:01 +02:00
|
|
|
|
2009-07-06 11:00:22 +02:00
|
|
|
for(i=0; i<input_len; i++) {
|
|
|
|
if(input[i] == '(') nest_level++;
|
|
|
|
else if(input[i] == ')') {
|
|
|
|
nest_level--;
|
2012-03-27 11:28:51 +02:00
|
|
|
if(nest_level<0) {
|
2012-05-29 12:53:55 +02:00
|
|
|
*ret = NAN;
|
2009-07-06 11:00:22 +02:00
|
|
|
return S_OK;
|
2012-03-27 11:28:51 +02:00
|
|
|
}
|
2009-07-06 11:00:22 +02:00
|
|
|
}
|
|
|
|
else if(!nest_level) parse_len++;
|
|
|
|
}
|
|
|
|
|
2012-10-11 12:17:37 +02:00
|
|
|
parse = heap_alloc((parse_len+1)*sizeof(WCHAR));
|
2009-07-06 11:00:22 +02:00
|
|
|
if(!parse)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
nest_level = 0;
|
|
|
|
parse_len = 0;
|
|
|
|
for(i=0; i<input_len; i++) {
|
|
|
|
if(input[i] == '(') nest_level++;
|
|
|
|
else if(input[i] == ')') nest_level--;
|
2019-06-06 09:17:49 +02:00
|
|
|
else if(!nest_level) parse[parse_len++] = towupper(input[i]);
|
2009-07-06 11:00:22 +02:00
|
|
|
}
|
2012-10-11 12:17:37 +02:00
|
|
|
parse[parse_len] = 0;
|
2009-07-06 11:00:22 +02:00
|
|
|
|
|
|
|
GetTimeZoneInformation(&tzi);
|
|
|
|
di.bias = tzi.Bias;
|
|
|
|
di.standardDate = tzi.StandardDate;
|
|
|
|
di.standardBias = tzi.StandardBias;
|
|
|
|
di.daylightDate = tzi.DaylightDate;
|
|
|
|
di.daylightBias = tzi.DaylightBias;
|
|
|
|
|
2012-10-11 12:17:37 +02:00
|
|
|
/* FIXME: Cache strings */
|
2009-07-06 11:00:22 +02:00
|
|
|
lcid_en = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
|
2018-07-09 20:59:12 +02:00
|
|
|
for(i=0; i<ARRAY_SIZE(string_ids); i++) {
|
2009-07-06 11:00:22 +02:00
|
|
|
size = GetLocaleInfoW(lcid_en, string_ids[i], NULL, 0);
|
2012-10-11 12:17:37 +02:00
|
|
|
strings[i] = heap_alloc((size+1)*sizeof(WCHAR));
|
2009-07-06 11:00:22 +02:00
|
|
|
if(!strings[i]) {
|
|
|
|
i--;
|
|
|
|
while(i-- >= 0)
|
2012-10-11 12:17:37 +02:00
|
|
|
heap_free(strings[i]);
|
|
|
|
heap_free(parse);
|
2009-07-06 11:00:22 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
GetLocaleInfoW(lcid_en, string_ids[i], strings[i], size);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<parse_len;) {
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
if(parse[i] == ',') {
|
|
|
|
while(parse[i] == ',') i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parse[i]>='0' && parse[i]<='9') {
|
2019-06-06 09:17:49 +02:00
|
|
|
int tmp = wcstol(&parse[i], NULL, 10);
|
2009-07-06 11:00:22 +02:00
|
|
|
while(parse[i]>='0' && parse[i]<='9') i++;
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
|
|
|
|
if(parse[i] == ':') {
|
|
|
|
/* Time */
|
|
|
|
if(set_hour) break;
|
|
|
|
set_hour = TRUE;
|
|
|
|
|
|
|
|
hour = tmp;
|
|
|
|
|
|
|
|
while(parse[i] == ':') i++;
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
if(parse[i]>='0' && parse[i]<='9') {
|
2019-06-06 09:17:49 +02:00
|
|
|
min = wcstol(&parse[i], NULL, 10);
|
2009-07-06 11:00:22 +02:00
|
|
|
while(parse[i]>='0' && parse[i]<='9') i++;
|
|
|
|
}
|
|
|
|
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
while(parse[i] == ':') i++;
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
if(parse[i]>='0' && parse[i]<='9') {
|
2019-06-06 09:17:49 +02:00
|
|
|
sec = wcstol(&parse[i], NULL, 10);
|
2009-07-06 11:00:22 +02:00
|
|
|
while(parse[i]>='0' && parse[i]<='9') i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(parse[i]=='-' || parse[i]=='/') {
|
2015-05-03 21:40:27 +02:00
|
|
|
/* Short or long date */
|
2009-07-06 11:00:22 +02:00
|
|
|
if(set_day || set_month || set_year) break;
|
|
|
|
set_day = TRUE;
|
|
|
|
set_month = TRUE;
|
|
|
|
set_year = TRUE;
|
|
|
|
|
|
|
|
month = tmp-1;
|
|
|
|
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
while(parse[i]=='-' || parse[i]=='/') i++;
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
if(parse[i]<'0' || parse[i]>'9') break;
|
2019-06-06 09:17:49 +02:00
|
|
|
day = wcstol(&parse[i], NULL, 10);
|
2009-07-06 11:00:22 +02:00
|
|
|
while(parse[i]>='0' && parse[i]<='9') i++;
|
|
|
|
|
|
|
|
while(parse[i]=='-' || parse[i]=='/') i++;
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2009-07-06 11:00:22 +02:00
|
|
|
if(parse[i]<'0' || parse[i]>'9') break;
|
2019-06-06 09:17:49 +02:00
|
|
|
year = wcstol(&parse[i], NULL, 10);
|
2009-07-06 11:00:22 +02:00
|
|
|
while(parse[i]>='0' && parse[i]<='9') i++;
|
2015-05-03 21:40:27 +02:00
|
|
|
|
|
|
|
if(tmp >= 70){
|
|
|
|
/* long date */
|
|
|
|
month = day - 1;
|
|
|
|
day = year;
|
|
|
|
year = tmp;
|
|
|
|
}
|
2009-07-06 11:00:22 +02:00
|
|
|
}
|
|
|
|
else if(tmp<0) break;
|
|
|
|
else if(tmp<70) {
|
|
|
|
/* Day */
|
|
|
|
if(set_day) break;
|
|
|
|
set_day = TRUE;
|
|
|
|
day = tmp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Year */
|
|
|
|
if(set_year) break;
|
|
|
|
set_year = TRUE;
|
|
|
|
year = tmp;
|
|
|
|
}
|
|
|
|
}
|
2016-05-21 12:41:40 +02:00
|
|
|
else if(parse[i]=='+' || parse[i]=='-') {
|
|
|
|
/* Timezone offset */
|
|
|
|
BOOL positive = TRUE;
|
|
|
|
|
|
|
|
if(set_offset && set_hour_adjust) break;
|
|
|
|
set_offset = TRUE;
|
|
|
|
set_hour_adjust = FALSE;
|
|
|
|
|
|
|
|
if(parse[i] == '-') positive = FALSE;
|
|
|
|
|
|
|
|
i++;
|
2019-06-06 09:17:49 +02:00
|
|
|
while(iswspace(parse[i])) i++;
|
2016-05-21 12:41:40 +02:00
|
|
|
if(parse[i]<'0' || parse[i]>'9') break;
|
2019-06-06 09:17:49 +02:00
|
|
|
offset = wcstol(&parse[i], NULL, 10);
|
2016-05-21 12:41:40 +02:00
|
|
|
while(parse[i]>='0' && parse[i]<='9') i++;
|
|
|
|
|
|
|
|
if(offset<24) offset *= 60;
|
|
|
|
else offset = (offset/100)*60 + offset%100;
|
|
|
|
|
|
|
|
if(positive) offset = -offset;
|
|
|
|
|
|
|
|
}
|
2009-07-06 11:00:22 +02:00
|
|
|
else {
|
|
|
|
if(parse[i]<'A' || parse[i]>'Z') break;
|
|
|
|
else if(parse[i]=='B' && (parse[i+1]=='C' ||
|
|
|
|
(parse[i+1]=='.' && parse[i+2]=='C'))) {
|
|
|
|
/* AD/BC */
|
|
|
|
if(set_era) break;
|
|
|
|
set_era = TRUE;
|
|
|
|
ad = FALSE;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if(parse[i] == '.') i++;
|
|
|
|
i++;
|
|
|
|
if(parse[i] == '.') i++;
|
|
|
|
}
|
|
|
|
else if(parse[i]=='A' && (parse[i+1]=='D' ||
|
|
|
|
(parse[i+1]=='.' && parse[i+2]=='D'))) {
|
|
|
|
/* AD/BC */
|
|
|
|
if(set_era) break;
|
|
|
|
set_era = TRUE;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if(parse[i] == '.') i++;
|
|
|
|
i++;
|
|
|
|
if(parse[i] == '.') i++;
|
|
|
|
}
|
|
|
|
else if(parse[i+1]<'A' || parse[i+1]>'Z') {
|
|
|
|
/* Timezone */
|
|
|
|
if(set_offset) break;
|
|
|
|
set_offset = TRUE;
|
|
|
|
|
|
|
|
if(parse[i] <= 'I') hour_adjust = parse[i]-'A'+2;
|
|
|
|
else if(parse[i] == 'J') break;
|
|
|
|
else if(parse[i] <= 'M') hour_adjust = parse[i]-'K'+11;
|
|
|
|
else if(parse[i] <= 'Y') hour_adjust = parse[i]-'N';
|
|
|
|
else hour_adjust = 1;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if(parse[i] == '.') i++;
|
|
|
|
}
|
|
|
|
else if(parse[i]=='A' && parse[i+1]=='M') {
|
|
|
|
/* AM/PM */
|
|
|
|
if(set_am) break;
|
|
|
|
set_am = TRUE;
|
|
|
|
am = TRUE;
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
else if(parse[i]=='P' && parse[i+1]=='M') {
|
|
|
|
/* AM/PM */
|
|
|
|
if(set_am) break;
|
|
|
|
set_am = TRUE;
|
|
|
|
am = FALSE;
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
else if((parse[i]=='U' && parse[i+1]=='T' && parse[i+2]=='C')
|
|
|
|
|| (parse[i]=='G' && parse[i+1]=='M' && parse[i+2]=='T')) {
|
|
|
|
/* Timezone */
|
|
|
|
if(set_offset) break;
|
|
|
|
set_offset = TRUE;
|
|
|
|
set_hour_adjust = FALSE;
|
|
|
|
|
|
|
|
i += 3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Month or garbage */
|
2013-02-09 23:32:02 +01:00
|
|
|
unsigned int j;
|
2009-07-06 11:00:22 +02:00
|
|
|
|
|
|
|
for(size=i; parse[size]>='A' && parse[size]<='Z'; size++);
|
|
|
|
size -= i;
|
|
|
|
|
2018-07-09 20:59:12 +02:00
|
|
|
for(j=0; j<ARRAY_SIZE(string_ids); j++)
|
2019-06-06 09:17:49 +02:00
|
|
|
if(!wcsnicmp(&parse[i], strings[j], size)) break;
|
2009-07-06 11:00:22 +02:00
|
|
|
|
|
|
|
if(j < 12) {
|
|
|
|
if(set_month) break;
|
|
|
|
set_month = TRUE;
|
|
|
|
month = 11-j;
|
|
|
|
}
|
2018-07-09 20:59:12 +02:00
|
|
|
else if(j == ARRAY_SIZE(string_ids)) break;
|
2009-07-06 11:00:22 +02:00
|
|
|
|
|
|
|
i += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
if(i == parse_len && set_year && set_month && set_day && (!set_am || hour<13)) {
|
2009-07-06 11:00:22 +02:00
|
|
|
if(set_am) {
|
|
|
|
if(hour == 12) hour = 0;
|
|
|
|
if(!am) hour += 12;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ad) year = -year+1;
|
|
|
|
else if(year<100) year += 1900;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
*ret = time_clip(make_date(make_day(year, month, day),
|
2009-07-06 11:00:22 +02:00
|
|
|
make_time(hour+hour_adjust, min, sec, ms)) + offset*MS_PER_MINUTE);
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
if(set_hour_adjust)
|
|
|
|
*ret = utc(*ret, &di);
|
|
|
|
}else {
|
2012-05-29 12:53:55 +02:00
|
|
|
*ret = NAN;
|
2009-07-06 11:00:22 +02:00
|
|
|
}
|
|
|
|
|
2018-07-09 20:59:12 +02:00
|
|
|
for(i=0; i<ARRAY_SIZE(string_ids); i++)
|
2012-10-11 12:17:37 +02:00
|
|
|
heap_free(strings[i]);
|
|
|
|
heap_free(parse);
|
2009-07-06 11:00:22 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT DateConstr_parse(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2009-07-03 02:45:12 +02:00
|
|
|
{
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_t *parse_str;
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2009-07-06 11:00:22 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(!argc) {
|
2012-09-17 15:16:20 +02:00
|
|
|
if(r)
|
|
|
|
*r = jsval_number(NAN);
|
2009-07-06 11:00:22 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_string(ctx, argv[0], &parse_str);
|
2009-07-06 11:00:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
hres = date_parse(parse_str, &n);
|
2012-10-11 12:16:01 +02:00
|
|
|
jsstr_release(parse_str);
|
2012-03-27 11:28:51 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_number(n);
|
2012-03-27 11:28:51 +02:00
|
|
|
return S_OK;
|
2009-07-03 02:45:12 +02:00
|
|
|
}
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
static HRESULT date_utc(script_ctx_t *ctx, unsigned argc, jsval_t *argv, double *ret)
|
2009-07-03 02:45:12 +02:00
|
|
|
{
|
2012-03-27 11:28:51 +02:00
|
|
|
double year, month, vdate, hours, minutes, seconds, ms;
|
2009-07-03 02:45:22 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[0], &year);
|
2009-07-03 02:45:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
if(0 <= year && year <= 99)
|
|
|
|
year += 1900;
|
|
|
|
}else {
|
|
|
|
year = 1900;
|
2009-07-03 02:45:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc>1) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[1], &month);
|
2009-07-03 02:45:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
month = 0;
|
2009-07-03 02:45:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc>2) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[2], &vdate);
|
2009-07-03 02:45:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
vdate = 1;
|
2009-07-03 02:45:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc>3) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[3], &hours);
|
2009-07-03 02:45:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
hours = 0;
|
2009-07-03 02:45:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc>4) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[4], &minutes);
|
2009-07-03 02:45:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
minutes = 0;
|
2009-07-03 02:45:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc>5) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[5], &seconds);
|
2009-07-03 02:45:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
}else {
|
|
|
|
seconds = 0;
|
2009-07-03 02:45:22 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 14:08:38 +02:00
|
|
|
if(argc>6) {
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, argv[6], &ms);
|
2009-07-03 02:45:22 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2012-03-27 11:28:51 +02:00
|
|
|
} else {
|
|
|
|
ms = 0;
|
2009-07-03 02:45:22 +02:00
|
|
|
}
|
|
|
|
|
2012-03-27 11:29:21 +02:00
|
|
|
*ret = time_clip(make_date(make_day(year, month, vdate),
|
|
|
|
make_time(hours, minutes,seconds, ms)));
|
2009-07-03 02:45:22 +02:00
|
|
|
return S_OK;
|
2009-07-03 02:45:12 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT DateConstr_UTC(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2009-09-23 16:13:44 +02:00
|
|
|
{
|
2012-03-27 11:29:21 +02:00
|
|
|
double n;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2009-09-23 16:13:44 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = date_utc(ctx, argc, argv, &n);
|
2012-09-17 15:16:20 +02:00
|
|
|
if(SUCCEEDED(hres) && r)
|
|
|
|
*r = jsval_number(n);
|
2012-03-27 11:29:21 +02:00
|
|
|
return hres;
|
2009-09-23 16:13:44 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 19:18:49 +01:00
|
|
|
/* ECMA-262 5.1 Edition 15.9.4.4 */
|
|
|
|
static HRESULT DateConstr_now(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if(r) *r = jsval_number(date_now());
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:42 +02:00
|
|
|
static HRESULT DateConstr_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
|
2012-09-18 19:01:49 +02:00
|
|
|
jsval_t *r)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *date;
|
2008-10-13 23:28:00 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
switch(flags) {
|
|
|
|
case DISPATCH_CONSTRUCT:
|
2012-06-25 14:08:38 +02:00
|
|
|
switch(argc) {
|
2008-10-13 23:28:00 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.3.3 */
|
2018-03-01 19:18:49 +01:00
|
|
|
case 0:
|
|
|
|
hres = create_date(ctx, NULL, date_now(), &date);
|
2008-10-13 23:28:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 15.9.3.2 */
|
|
|
|
case 1: {
|
2012-09-17 15:17:50 +02:00
|
|
|
jsval_t prim;
|
2012-03-27 11:28:51 +02:00
|
|
|
double n;
|
2008-10-13 23:28:00 +02:00
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_primitive(ctx, argv[0], &prim, NO_HINT);
|
2008-10-13 23:28:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-09-17 15:17:50 +02:00
|
|
|
if(is_string(prim))
|
|
|
|
hres = date_parse(get_string(prim), &n);
|
2009-07-06 10:38:08 +02:00
|
|
|
else
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = to_number(ctx, prim, &n);
|
2008-10-13 23:28:00 +02:00
|
|
|
|
2012-09-17 15:17:50 +02:00
|
|
|
jsval_release(prim);
|
2008-10-13 23:28:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-03-27 11:28:51 +02:00
|
|
|
hres = create_date(ctx, NULL, time_clip(n), &date);
|
2008-10-13 23:28:00 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-06-22 20:40:01 +02:00
|
|
|
/* ECMA-262 3rd Edition 15.9.3.1 */
|
|
|
|
default: {
|
2012-03-27 11:29:21 +02:00
|
|
|
double ret_date;
|
2009-06-22 20:40:01 +02:00
|
|
|
DateInstance *di;
|
|
|
|
|
2012-09-18 19:01:49 +02:00
|
|
|
hres = date_utc(ctx, argc, argv, &ret_date);
|
2009-09-23 16:13:44 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2009-06-22 20:40:01 +02:00
|
|
|
|
2012-03-27 11:29:21 +02:00
|
|
|
hres = create_date(ctx, NULL, ret_date, &date);
|
2009-06-22 20:40:01 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2016-09-22 09:56:28 +02:00
|
|
|
di = date_from_jsdisp(date);
|
2009-06-22 20:40:01 +02:00
|
|
|
di->time = utc(di->time, di);
|
|
|
|
}
|
2008-10-13 23:28:00 +02:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
*r = jsval_obj(date);
|
2008-10-13 23:28:00 +02:00
|
|
|
return S_OK;
|
|
|
|
|
2009-07-06 10:38:14 +02:00
|
|
|
case INVOKE_FUNC: {
|
|
|
|
FILETIME system_time, local_time;
|
|
|
|
LONGLONG lltime;
|
|
|
|
|
|
|
|
GetSystemTimeAsFileTime(&system_time);
|
|
|
|
FileTimeToLocalFileTime(&system_time, &local_time);
|
|
|
|
lltime = ((LONGLONG)local_time.dwHighDateTime<<32)
|
|
|
|
+ local_time.dwLowDateTime;
|
|
|
|
|
2012-09-17 15:16:20 +02:00
|
|
|
return date_to_string(lltime/10000-TIME_EPOCH, FALSE, 0, r);
|
2009-07-06 10:38:14 +02:00
|
|
|
}
|
|
|
|
|
2008-10-13 23:28:00 +02:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2008-09-30 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
2009-07-03 02:45:12 +02:00
|
|
|
static const builtin_prop_t DateConstr_props[] = {
|
|
|
|
{UTCW, DateConstr_UTC, PROPF_METHOD},
|
2018-03-01 19:18:49 +01:00
|
|
|
{nowW, DateConstr_now, PROPF_HTML|PROPF_METHOD},
|
2009-07-03 02:45:12 +02:00
|
|
|
{parseW, DateConstr_parse, PROPF_METHOD}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const builtin_info_t DateConstr_info = {
|
|
|
|
JSCLASS_FUNCTION,
|
2015-02-05 14:49:01 +01:00
|
|
|
DEFAULT_FUNCTION_VALUE,
|
2018-07-09 20:59:12 +02:00
|
|
|
ARRAY_SIZE(DateConstr_props),
|
2009-07-03 02:45:12 +02:00
|
|
|
DateConstr_props,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-09-06 16:11:49 +02:00
|
|
|
HRESULT create_date_constr(script_ctx_t *ctx, jsdisp_t *object_prototype, jsdisp_t **ret)
|
2008-09-30 17:48:18 +02:00
|
|
|
{
|
2010-09-06 16:11:49 +02:00
|
|
|
jsdisp_t *date;
|
2008-09-30 17:48:18 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2009-09-17 01:04:44 +02:00
|
|
|
static const WCHAR DateW[] = {'D','a','t','e',0};
|
|
|
|
|
2009-08-14 11:53:57 +02:00
|
|
|
hres = create_date(ctx, object_prototype, 0.0, &date);
|
2008-09-30 17:48:18 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2012-07-16 15:31:10 +02:00
|
|
|
hres = create_builtin_constructor(ctx, DateConstr_value, DateW, &DateConstr_info,
|
2009-10-13 22:08:43 +02:00
|
|
|
PROPF_CONSTR|7, date, ret);
|
2008-09-30 17:48:18 +02:00
|
|
|
|
|
|
|
jsdisp_release(date);
|
|
|
|
return hres;
|
|
|
|
}
|