Author: Stephan <[email protected]>
Branch:
Changeset: r250:def03958f695
Date: 2012-06-05 18:30 +0200
http://bitbucket.org/pypy/lang-js/changeset/def03958f695/
Log: fixed Date
diff --git a/js/builtins_date.py b/js/builtins_date.py
--- a/js/builtins_date.py
+++ b/js/builtins_date.py
@@ -93,7 +93,8 @@
def to_string(this, args):
d = w_date_to_datetime(this)
local = to_local(d)
- s = local.strftime('%c %z')
+
+ s = local.strftime('%a %b %d %Y %H:%M:%S GMT%z (%Z)')
return s
# 15.9.5.8
@@ -195,7 +196,7 @@
# 15.9.5.26
def get_timezone_offset(this, args):
d = w_date_to_datetime(this)
- offset = -1 * (d.utcoffset().to_seconds() / 60)
+ offset = -1 * (d.utcoffset().total_seconds() / 60)
return offset
# 15.9.5.27
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -641,7 +641,6 @@
class W_DateObject(W__PrimitiveObject):
_class_ = 'Date'
-
def default_value(self, hint = 'String'):
if hint is None:
hint = 'String'
@@ -793,9 +792,36 @@
# 15.9.2
class W_DateConstructor(W_BasicFunction):
def Call(self, args=[], this=None):
+ from js.builtins import get_arg
import time
- now = _w(int(time.time() * 1000))
- return W_DateObject(now)
+ import datetime
+
+ if len(args) > 1:
+ arg0 = get_arg(args, 0);
+ arg1 = get_arg(args, 1, _w(0));
+ arg2 = get_arg(args, 2, _w(0));
+
+ year = arg0.ToInteger()
+ month = arg1.ToInteger() + 1
+ day = arg2.ToInteger() + 1
+
+ d = datetime.date(year, month, day)
+ sec = time.mktime(d.timetuple())
+ value = _w(int(sec * 1000))
+
+ elif len(args) == 1:
+ arg0 = get_arg(args, 0);
+ if isinstance(arg0, W_String):
+ raise NotImplementedError()
+ else:
+ num = arg0.ToNumber()
+ if isnan(num) or isinf(num):
+ raise JsTypeError(num)
+ value = _w(int(num))
+ else:
+ value = _w(int(time.time() * 1000))
+
+ return W_DateObject(value)
# 15.7.2.1
def Construct(self, args=[]):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit