Piotr Caban : jscript: Added Date_getDate and Date_getUTCDate implementation.
Alexandre Julliard
julliard at winehq.org
Wed Jun 10 10:16:57 CDT 2009
Module: wine
Branch: master
Commit: 190ed2ef99bc5a20afc8a193d5b37588062bf01a
URL: http://source.winehq.org/git/wine.git/?a=commit;h=190ed2ef99bc5a20afc8a193d5b37588062bf01a
Author: Piotr Caban <piotr.caban at gmail.com>
Date: Tue Jun 9 14:04:09 2009 +0200
jscript: Added Date_getDate and Date_getUTCDate implementation.
---
dlls/jscript/date.c | 56 +++++++++++++++++++++++++++++++++++++++++---
dlls/jscript/tests/api.js | 4 +++
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/dlls/jscript/date.c b/dlls/jscript/date.c
index d018a10..84d4170 100644
--- a/dlls/jscript/date.c
+++ b/dlls/jscript/date.c
@@ -182,6 +182,30 @@ static inline DOUBLE month_from_time(DOUBLE time)
return 11;
}
+/* ECMA-262 3th Edition 15.9.1.5 */
+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))
+ return ret_nan();
+
+ 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;
+}
+
/* ECMA-262 3rd Edition 15.9.1.14 */
static inline DOUBLE time_clip(DOUBLE time)
{
@@ -363,18 +387,42 @@ static HRESULT Date_getUTCMonth(DispatchEx *dispex, LCID lcid, WORD flags, DISPP
return S_OK;
}
+/* ECMA-262 3th Edition 15.9.1.5 */
static HRESULT Date_getDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
- FIXME("\n");
- return E_NOTIMPL;
+ TRACE("\n");
+
+ if(!is_class(dispex, JSCLASS_DATE)) {
+ FIXME("throw TypeError\n");
+ return E_FAIL;
+ }
+
+ if(retv) {
+ DateInstance *date = (DateInstance*)dispex;
+ DOUBLE time = date->time - date->bias*MS_PER_MINUTE;
+
+ num_set_val(retv, date_from_time(time));
+ }
+ return S_OK;
}
+/* ECMA-262 3th Edition 15.9.1.5 */
static HRESULT Date_getUTCDate(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
- FIXME("\n");
- return E_NOTIMPL;
+ TRACE("\n");
+
+ if(!is_class(dispex, JSCLASS_DATE)) {
+ FIXME("throw TypeError\n");
+ return E_FAIL;
+ }
+
+ if(retv) {
+ DateInstance *date = (DateInstance*)dispex;
+ num_set_val(retv, date_from_time(date->time));
+ }
+ return S_OK;
}
static HRESULT Date_getDay(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 1a10863..8616cc0 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -948,16 +948,20 @@ ok(isNaN(date.setTime(NaN)), "date.setTime(NaN) is not NaN");
ok(date.setTime(0) === date.getTime(), "date.setTime(0) !== date.getTime()");
ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
ok(date.getUTCMonth() === 0, "date.getUTCMonth() = " + date.getUTCMonth());
+ok(date.getUTCDate() === 1, "date.getUTCDate() = " + date.getUTCDate());
date.setTime(60*24*60*60*1000);
ok(date.getUTCFullYear() === 1970, "date.getUTCFullYear() = " + date.getUTCFullYear());
ok(date.getUTCMonth() === 2, "date.getUTCMonth() = " + date.getUTCMonth());
+ok(date.getUTCDate() === 2, "date.getUTCDate() = " + date.getUTCDate());
date.setTime(59*24*60*60*1000 + 4*365*24*60*60*1000);
ok(date.getUTCFullYear() === 1974, "date.getUTCFullYear() = " + date.getUTCFullYear());
ok(date.getUTCMonth() === 1, "date.getUTCMonth() = " + date.getUTCMonth());
ok(date.getUTCMonth(123) === 1, "date.getUTCMonth() = " + date.getUTCMonth());
+ok(date.getUTCDate() === 28, "date.getUTCDate() = " + date.getUTCDate());
date.setTime(Infinity);
ok(isNaN(date.getUTCFullYear()), "date.getUTCFullYear() is not NaN");
ok(isNaN(date.getUTCMonth()), "date.getUTCMonth() is not NaN");
+ok(isNaN(date.getUTCDate()), "date.getUTCDate() is not NaN");
ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI));
ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI);
More information about the wine-cvs
mailing list