Add Date.toISOString (sdgoij)

This commit is contained in:
Robert Krimen
2013-06-15 12:06:33 -07:00
parent 14b2fb3918
commit a34c4d2d1f
4 changed files with 42 additions and 0 deletions

View File

@@ -61,6 +61,14 @@ func builtinDate_toUTCString(call FunctionCall) Value {
return toValue(date.Time().Format(builtinDate_goDateTimeLayout))
}
func builtinDate_toISOString(call FunctionCall) Value {
date := dateObjectOf(call.thisObject())
if date.isNaN {
return toValue("Invalid Date")
}
return toValue(date.Time().Format("2006-01-02T15:04:05.000Z"))
}
func builtinDate_toGMTString(call FunctionCall) Value {
date := dateObjectOf(call.thisObject())
if date.isNaN {

View File

@@ -125,6 +125,13 @@ func TestDate_UTC(t *testing.T) {
test(`Date.UTC(2009, 9, 25)`, "1256428800000")
}
func TestDate_toISOString(t *testing.T) {
Terst(t)
test := runTest()
test(`new Date(0).toISOString()`, "1970-01-01T00:00:00.000Z")
}
func TestDate_setYear(t *testing.T) {
Terst(t)

1
inline
View File

@@ -367,6 +367,7 @@ sub newContext {
"toDateString", 0,
"toTimeString", 0,
"toUTCString", 0,
"toISOString", 0,
"toGMTString", 0,
"toLocaleString", 0,
"toLocaleDateString", 0,

View File

@@ -2509,6 +2509,25 @@ func _newContext(runtime *_runtime) {
call: _nativeCallFunction(builtinDate_toUTCString),
},
}
toISOString_function := &_object{
runtime: runtime,
class: "Function",
objectClass: _classObject,
prototype: runtime.Global.FunctionPrototype,
extensible: true,
property: map[string]_property{
"length": _property{
mode: 0,
value: Value{
_valueType: valueNumber,
value: 0,
},
},
},
value: _functionObject{
call: _nativeCallFunction(builtinDate_toISOString),
},
}
toGMTString_function := &_object{
runtime: runtime,
class: "Function",
@@ -3343,6 +3362,13 @@ func _newContext(runtime *_runtime) {
value: toUTCString_function,
},
},
"toISOString": _property{
mode: 0101,
value: Value{
_valueType: valueObject,
value: toISOString_function,
},
},
"toGMTString": _property{
mode: 0101,
value: Value{