mirror of
https://github.com/robertkrimen/otto.git
synced 2025-12-24 12:58:05 +08:00
Add Date.toISOString (sdgoij)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
1
inline
@@ -367,6 +367,7 @@ sub newContext {
|
||||
"toDateString", 0,
|
||||
"toTimeString", 0,
|
||||
"toUTCString", 0,
|
||||
"toISOString", 0,
|
||||
"toGMTString", 0,
|
||||
"toLocaleString", 0,
|
||||
"toLocaleDateString", 0,
|
||||
|
||||
26
inline.go
26
inline.go
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user