diff --git a/builtin_date.go b/builtin_date.go index c064771..a5cb2da 100644 --- a/builtin_date.go +++ b/builtin_date.go @@ -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")) +} diff --git a/date_test.go b/date_test.go index 59f562c..8b93d31 100644 --- a/date_test.go +++ b/date_test.go @@ -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") diff --git a/global.go b/global.go index 1293b57..fab0c4a 100644 --- a/global.go +++ b/global.go @@ -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 {