mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Add Date.getYear
This commit is contained in:
parent
a5ae851516
commit
d5497fbe89
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue
Block a user