mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Add Date.toLocale*String
This commit is contained in:
parent
9281104552
commit
d223d7576f
|
@ -74,3 +74,30 @@ func builtinDate_parse(call FunctionCall) Value {
|
|||
func builtinDate_UTC(call FunctionCall) Value {
|
||||
return toValue(newDateTime(call.ArgumentList))
|
||||
}
|
||||
|
||||
// This is a placeholder
|
||||
func builtinDate_toLocaleString(call FunctionCall) Value {
|
||||
date := dateObjectOf(call.thisObject())
|
||||
if date.isNaN {
|
||||
return toValue("Invalid Date")
|
||||
}
|
||||
return toValue(date.Time().Local().Format("2006-01-02 15:04:05"))
|
||||
}
|
||||
|
||||
// This is a placeholder
|
||||
func builtinDate_toLocaleDateString(call FunctionCall) Value {
|
||||
date := dateObjectOf(call.thisObject())
|
||||
if date.isNaN {
|
||||
return toValue("Invalid Date")
|
||||
}
|
||||
return toValue(date.Time().Local().Format("2006-01-02"))
|
||||
}
|
||||
|
||||
// This is a placeholder
|
||||
func builtinDate_toLocaleTimeString(call FunctionCall) Value {
|
||||
date := dateObjectOf(call.thisObject())
|
||||
if date.isNaN {
|
||||
return toValue("Invalid Date")
|
||||
}
|
||||
return toValue(date.Time().Local().Format("15:04:05"))
|
||||
}
|
||||
|
|
|
@ -19,6 +19,12 @@ func TestDate(t *testing.T) {
|
|||
|
||||
test(`Date`, "[function]")
|
||||
test(`new Date(0).toUTCString()`, "Thu, 01 Jan 1970 00:00:00 UTC")
|
||||
if false {
|
||||
// TODO
|
||||
test(`new Date(0).toLocaleString()`, "")
|
||||
test(`new Date(0).toLocaleDateString()`, "")
|
||||
test(`new Date(0).toLocaleTimeString()`, "")
|
||||
}
|
||||
test(`new Date(1348616313).getTime()`, "1348616313")
|
||||
test(`new Date(1348616313).toUTCString()`, "Fri, 16 Jan 1970 14:36:56 UTC")
|
||||
test(`abc = new Date(1348616313047); abc.toUTCString()`, "Tue, 25 Sep 2012 23:38:33 UTC")
|
||||
|
|
|
@ -348,6 +348,9 @@ func newContext() *_runtime {
|
|||
self.Global.DatePrototype,
|
||||
"toString", 0, builtinDate_toString,
|
||||
"toUTCString", 0, builtinDate_toUTCString,
|
||||
"toLocaleString", 0, builtinDate_toLocaleString,
|
||||
"toLocaleDateString", 0, builtinDate_toLocaleDateString,
|
||||
"toLocaleTimeString", 0, builtinDate_toLocaleTimeString,
|
||||
"valueOf", 0, func(call FunctionCall) Value {
|
||||
date := dateObjectOf(call.thisObject())
|
||||
if date.isNaN {
|
||||
|
|
Loading…
Reference in New Issue
Block a user