From f2319fcd85a18f22f49914c2059843bfda1199b9 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 20 Dec 2010 12:21:42 +0100 Subject: [PATCH] jscript: Added Date.setYear implementation. --- dlls/jscript/date.c | 38 ++++++++++++++++++++++++++++++++++++-- dlls/jscript/tests/api.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c index 3be8a36ffa9..e9542f813c0 100644 --- a/dlls/jscript/date.c +++ b/dlls/jscript/date.c @@ -2028,8 +2028,42 @@ static HRESULT Date_getYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP static HRESULT Date_setYear(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller) { - FIXME("\n"); - return E_NOTIMPL; + DateInstance *date; + DOUBLE t, year; + VARIANT v; + HRESULT hres; + + TRACE("\n"); + + if(!(date = date_this(jsthis))) + return throw_type_error(ctx, ei, IDS_NOT_DATE, NULL); + + if(!arg_cnt(dp)) + return throw_type_error(ctx, ei, IDS_ARG_NOT_OPT, NULL); + + t = local_time(date->time, date); + + hres = to_number(ctx, get_arg(dp, 0), ei, &v); + if(FAILED(hres)) + return hres; + + year = num_val(&v); + if(isnan(year)) { + date->time = year; + if(retv) + num_set_nan(retv); + 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)); + + if(retv) + num_set_val(retv, date->time); + return S_OK; } static HRESULT Date_value(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp, diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index f35d11a9e94..081582ef0e7 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -1597,6 +1597,7 @@ ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours()); ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes()); ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds()); ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); + date.setTime(60*24*60*60*1000); ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear()); ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth()); @@ -1606,6 +1607,7 @@ ok(date.getUTCHours() === 0, "date.getUTCHours() = " + date.getUTCHours()); ok(date.getUTCMinutes() === 0, "date.getUTCMinutes() = " + date.getUTCMinutes()); ok(date.getUTCSeconds() === 0, "date.getUTCSeconds() = " + date.getUTCSeconds()); ok(date.getUTCMilliseconds() === 0, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); + date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000 + 60*60*1000 + 2*60*1000 + 2*1000 + 640); ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear()); ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth()); @@ -1616,6 +1618,22 @@ ok(date.getUTCHours() === 1, "date.getUTCHours() = " + date.getUTCHours()); ok(date.getUTCMinutes() === 2, "date.getUTCMinutes() = " + date.getUTCMinutes()); ok(date.getUTCSeconds() === 2, "date.getUTCSeconds() = " + date.getUTCSeconds()); ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); + +tmp = date.setYear(96); +ok(date.getYear() === 96, "date.getYear() = " + date.getYear()); +ok(date.getFullYear() === 1996, "date.getFullYear() = " + date.getYear()); +ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth()); +ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth()); +ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); + +tmp = date.setYear(2010); +ok(tmp === date.getTime(), "date.setYear(2010) = " + tmp); +ok(date.getYear() === 2010, "date.getYear() = " + date.getYear()); +ok(date.getFullYear() === 2010, "date.getFullYear() = " + date.getYear()); +ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth()); +ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth()); +ok(date.getUTCMilliseconds() === 640, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); + date.setTime(Infinity); ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN"); ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN"); @@ -1627,6 +1645,12 @@ ok(isNaN(date.getUTCSeconds()), "date.getUTCSeconds() is not NaN"); ok(isNaN(date.getUTCMilliseconds()), "date.getUTCMilliseconds() is not NaN"); ok(isNaN(date.setMilliseconds(0)), "date.setMilliseconds() is not NaN"); +date.setTime(0); +tmp = date.setYear(NaN); +ok(isNaN(tmp), "date.setYear(NaN) = " + tmp); +ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN"); +ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN"); + date.setTime(0); date.setUTCMilliseconds(-10, 2); ok(date.getUTCMilliseconds() === 990, "date.getUTCMilliseconds() = " + date.getUTCMilliseconds()); @@ -1863,6 +1887,7 @@ exception_test(function() {arr.toString = Date.prototype.toString; arr.toString( exception_test(function() {Array(-3);}, "RangeError", -2146823259); exception_test(function() {arr.toString = Boolean.prototype.toString; arr.toString();}, "TypeError", -2146823278); exception_test(function() {date.setTime();}, "TypeError", -2146827839); +exception_test(function() {date.setYear();}, "TypeError", -2146827839); exception_test(function() {arr.test();}, "TypeError", -2146827850); exception_test(function() {arr.toString = Number.prototype.toString; arr.toString();}, "TypeError", -2146823287); exception_test(function() {(new Number(3)).toString(1);}, "TypeError", -2146828283); @@ -1939,6 +1964,7 @@ testDateThis("getUTCMilliseconds"); testDateThis("getUTCMinutes"); testDateThis("getUTCMonth"); testDateThis("getUTCSeconds"); +testDateThis("getYear"); testDateThis("setDate"); testDateThis("setFullYear"); testDateThis("setHours"); @@ -1954,6 +1980,7 @@ testDateThis("setUTCMilliseconds"); testDateThis("setUTCMinutes"); testDateThis("setUTCMonth"); testDateThis("setUTCSeconds"); +testDateThis("setYear"); testDateThis("toDateString"); testDateThis("toLocaleDateString"); testDateThis("toLocaleString"); @@ -2121,6 +2148,7 @@ testFunctions(Date.prototype, [ ["getUTCMinutes", 0], ["getUTCMonth", 0], ["getUTCSeconds", 0], + ["getYear", 0], ["setDate", 1], ["setFullYear", 3], ["setHours", 4],