diff --git a/date_test.go b/date_test.go index dda64ff..c88bac2 100644 --- a/date_test.go +++ b/date_test.go @@ -22,6 +22,7 @@ func TestDate(t *testing.T) { 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") + check(`abc.getYear()`, time.Year()-1900) check(`abc.getFullYear()`, time.Year()) check(`abc.getUTCFullYear()`, 2012) check(`abc.getMonth()`, int(time.Month())-1) // Remember, the JavaScript month is 0-based diff --git a/global.go b/global.go index 02c2e3e..b5d6de5 100644 --- a/global.go +++ b/global.go @@ -357,6 +357,15 @@ func newContext() *_runtime { }, // getTime, ... "getTime", 0, builtinDate_getTime, + "getYear", 0, func(call FunctionCall) Value { + // Will throw a TypeError is ThisObject is nil or + // does not have Class of "Date" + date := dateObjectOf(call.thisObject()) + if date.isNaN { + return NaNValue() + } + return toValue(date.Time().Local().Year() - 1900) + }, "getFullYear", 0, func(call FunctionCall) Value { // Will throw a TypeError is ThisObject is nil or // does not have Class of "Date"